Embperl - building dynamic websites with Perl

Error trapping
[ << Prev: Encoding/UTF-8 ] [ Content ] [ Next: Utility Functions >> ]

When an error occurs inside an Embperl page, Embperl will display an error page, containing the error message.

Sometimes you want to have a different behaviour. One possibility is to let Apache display a custom error page (of course only when you run under mod_perl).

To get this working you need to set the option optReturnError (262144) in your httpd.conf in the EMBPERL_OPTIONS directive.

With this option set, Embperl sends no output in case of an error. It returns the error back to Apache or the calling program. When running under mod_perl this gives you the chance to use the Apache ErrorDocument directive to show a custom error-document. Inside the ErrorDocument you can retrieve the error messages with

  $errors = $req_rec -> prev -> pnotes('EMBPERL_ERRORS') ;

where $errors is a array reference.

If you want to trap exceptions in a Embperl document, that you call via Execute, you can do this by passing an array to Execute, which receives all error/warning messages and/or all error objects.

    Execute ({inputfile => 'foo.epl', errors => \@errors}) ;
    [$if @errors$]
        The following errors had occurred:<br>
        [$foreach $err (@errors)$]
            [+ $err +]<br>         

In case you call die inside the executed page and pass an object (or a reference) to die instead of a string this will also show up in @errors. The last object passed to die is also available via $epreq - errobj>.

$epreq - error> can be used to test if an error occurred so far during the current request. You can also set $epreq - error> to false to reset Embperl's internal error condition.

If the option optReturnError or an error array is passed to a component the error flag is reset after the execution of component.

If an error array is passed to a component, the errors inside the component are not added to the overall errors of the request and therefore will not cause Embperl to display an error page.

An more seldom used option is optDisableEmbperlErrorPage (2), which tells tells Embperl not to send its own errorpage in case of failure, but instead show as much of the page as possible. Errors are only logged to the log file.

[ << Prev: Encoding/UTF-8 ] [ Content ] [ Next: Utility Functions >> ]

© 1997-2023 Gerald Richter / actevy