Coding Domain

Perl Modules: CGI::ErrorTrap


Downloads
Perl Modules
Name
CGI::ErrorTrap - Display advanced error messages

Synopsis
use CGI::ErrorTrap;

[*(\{] # propertly syntax error ;-)

warn "The program ends here!\n";
die "HAHA!\n";

Error('Failed to...');
Error('Error in program X', 'Failed to...');

DESCRIPTION

Traps errors in CGI programs, and displays an better error dialog.

Functions and Variables
Error( 'optional_title', 'error message');
This is the error handler used when errors are trapped. The optional title will be displayed in the header of the dialog. This subroutine can also be called as an single argument version, like &Error('error message'). The text 'Unexpected Error' will then be displayed in stead of the title.

IsRealError()
This subroutine should only be called inside any $SIG{'__DIE__'} or $SIG{'__WARN__'} handler. It returns false when the signal handler was activated inside an eval statement. Normally, you shouldn't respond to such errors.

$CGI::ErrorTrap::DIALOG_SUB
If this variable is set to a code pointer, that code will be ordered to display the error dialog. All tests and message conversions are already done. The subroutine will get two parameters; a title and a real error message.

$CGI::ErrorTrap::DISPLAY_FULL
Defaultly set to True. This implies that more debugging information should be printed at the screen. Sometimes, this value will be forced or overruled. The value should be set to false as soon as some HTML text has been printed to the screen.

$main::BACK_COLOR, $main::FONT_COLOR
If these values are available, they will be used to format the error window. If you want to display a more personal error message dialog, you should use the $CGI::ErrorTrap::DIALOG_SUB variable.

$main::THIS_PATH, $main::THIS_UPPATH
These values are added by the CGI::Location module. They won't be displayed, but they are used in a regexp to hide all paths from the error message. It's more safe to use the message, and it clears up the message a bit.

Other Issues
Both the warn and die messages will be trapped, what I consider useful in CGI programs. This error trap will be active, even before any BEGIN block of the main program is executed! Thus, (almost) all error messages will be trapped, and complication errors aswell.

Author
Copyright (c) 2001, Diederik van der Boor - All Rights Reserved