# man > CGI::Application::Plugin::ErrorPage(3pm)

---
type: CommandReference
command: CGI::Application::Plugin::ErrorPage
mode: perldoc
section: 3pm
source: perldoc
---

## Quick Reference

- `use CGI::Application::Plugin::ErrorPage 'error';` — import the `error` method
- `$self->error(title => "Error Title", msg => "Error message")` — return an error page using default `error.html` template
- `$self->error(tmpl => '/path/to/error.html', title => ..., msg => ...)` — use a custom error template
- Plugin automatically installs a default AUTOLOAD run mode that returns an error page for missing run modes

## Name

CGI::Application::Plugin::ErrorPage - A simple error page plugin for CGI::Application

## Synopsis

perl
use CGI::Application::Plugin::ErrorPage 'error';

sub my_run_mode {
    my $self = shift;
    eval { ... };
    if ($@) {
        warn "$@";
        return $self->error(
            title => "Technical Failure",
            msg   => "There was a technical failure during the operation.",
        );
    }
}
## Description

This plugin provides a shortcut for returning a simple error message to the user. It encourages using a template file (`error.html`) for consistent design. If no `AUTOLOAD` run mode is installed, the plugin automatically installs a reasonable default at the `prerun` stage that returns an error page for missing run modes.

### Relation to `error_mode()`

CGI::Application includes `error_mode()` for custom handling when the application dies. The `error()` routine is for displaying error messages to the user. They can be used together: in your `error_mode` routine, you might call `error()` to return a message to the user.

### Suggested Uses

- Technical Failure: unexpected software failure
- Insufficient Information: missing required query parameter
- Request Not Understood: invalid query value

## Methods

### `error()`

perl
return $self->error(
    title => "Technical Failure",
    msg   => "There was a technical failure during the operation",
);
A shortcut to load a template meant to display errors. It tries to load a template file named `error.html`. If you want a different location, override `error` in your base class:

perl
use CGI::Application::Plugin::ErrorPage;
sub error {
    my $c = shift;
    return $c->CGI::Application::Plugin::ErrorPage::error(
        tmpl => $self->cfg('ROOT_URI') . '/path/to/my/alternate/error/file.html',
        @_,
    );
}
This module intentionally ignores any `tmpl_path()` set by the application, since that usually indicates the location of intended files, not the error template. If you don't want this behavior, roll your own:

perl
use Params::Validate ':all';
sub error {
    my $self = shift;
    my %p = validate(@_, { title => SCALAR, msg => SCALAR });
    my $t = $self->load_tmpl;
    $t->param( title => $p{title}, msg => $p{msg} );
    return $t->output;
}
### Example `error.html`

html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title><!-- tmpl_var title escape=HTML --></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<h1><!-- tmpl_var title escape=HTML--></h1>
<p><!-- tmpl_var msg escape=HTML --></p>
</body>
</html>
## See Also

- [perl](http://localhost/phpMan.php/man/perl/1/markdown)
- [CGI::Application](http://localhost/phpMan.php/perldoc/CGI%3A%3AApplication/markdown)

## Support

Ask for help on the CGI::Application mailing list. Report bugs and wishes through the rt.cpan.org bug tracker.

## Author

Mark Stosberg (CPAN ID: MARKSTOS, <mark@summersault.com>)

## Copyright

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.