# info > CGI::Application::Plugin::ErrorPage

---
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
- `return $self->error(title => 'Error', msg => 'Description');` — display an error page
- `eval { ... }; if ($@) { warn $@; return $self->error(...); }` — catch exceptions and show a user-friendly message
- `$self->error(tmpl => '/path/to/custom/error.html', title => ..., msg => ...);` — use a custom error template
- `$self->error(title => 'Not Found', msg => 'Page: '. $self->get_current_runmode);` — default “page not found” response (installed automatically if no AUTOLOAD run mode exists)

## 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.',
        );
    }
}
## Methods
- `error(%params)` — Loads the error template (default: `error.html`), populates it with the provided `title` and `msg` parameters, and returns the rendered output.  
  Required parameters: `title` (scalar), `msg` (scalar).  
  Optional parameter: `tmpl` — an explicit template file path; bypasses the default `error.html`.  
  The method intentionally ignores any `tmpl_path()` set by the application so that the error template is always found in a predictable location.  
  If you do not define an `AUTOLOAD` run mode, this plugin automatically installs one at the `prerun` stage that returns an error page with a “page not found” message.

## Examples

### Simple error in a run mode
perl
sub do_stuff {
    my $self = shift;
    if ($missing_param) {
        return $self->error(
            title => 'Insufficient Information',
            msg   => 'Missing required parameter: id',
        );
    }
}
### Using with error_mode
perl
sub setup {
    my $self = shift;
    $self->error_mode('handle_error');
}

sub handle_error {
    my $self = shift;
    return $self->error(
        title => 'Unexpected Error',
        msg   => 'An internal error occurred. Please try again later.',
    );
}
### Custom error template location
perl
# In a base class – don't import 'error' to avoid a redefinition warning
use CGI::Application::Plugin::ErrorPage;
sub error {
    my $c = shift;
    return $c->CGI::Application::Plugin::ErrorPage::error(
        tmpl  => $c->cfg('ROOT_URI') . '/alternate/error.html',
        @_,
    );
}
## See Also
- [CGI::Application](https://metacpan.org/pod/CGI::Application)
- [Params::Validate](https://metacpan.org/pod/Params::Validate)