Banky has asked for the wisdom of the Perl Monks concerning the following question:

I've developed a web application using CGI::Application. Now I'm looking to override the default behavior of writing error messages to the screen.

I'd like to give the user a nice looking error screen with possibly an automatically generated error number.

Then I'd like to log the error to a file and possibly the database.

How would I go about doing this?

  • Comment on How do I override the error display of a CGI::Application

Replies are listed 'Best First'.
Re: How do I override the error display of a CGI::Application
by Anonymous Monk on Nov 20, 2001 at 04:04 UTC
    I have just started using CGI::Application (and am loving it). And my best guess would be to use the AUTOLOAD run mode. I don't know if this is the correct way of solving this, though I think it is.

    Quoted from the CGI::Application documentation:

            THE RUN-MODE OF LAST RESORT: "AUTOLOAD"
    
            If CGI::Application is asked to go to a run-mode which doesn't exist
            it will usually croak() with errors. If this is not your desired
            behavior, it is possible to catch this exception by implementing a
            run-mode with the reserved name "AUTOLOAD":
    
              $self->run_modes(
                    "AUTOLOAD" => \&catch_my_exception
              );
    
            Before CGI::Application called croak() it will check for the
            existance of a run-mode called "AUTOLOAD". If specified, this
            run-mode will in involked just like a regular run-mode, with one
            exception: It will receive, as an argument, the name of the run-mode
            which involked it:
    
              sub catch_my_exception {
                    my $self = shift;
                    my $intended_runmode = shift;
    
                    my $output = "Looking for '$intended_runmode', but found 'AUTOLOAD' instead";
                    return $output;
              } 
    
            This functionality could be used for a simple human-readable error
            screen, or for more sophisticated application behaviors.