Keep It Simple, Stupid | |
PerlMonks |
How can I get better error messages from a CGI program?by faq_monk (Initiate) |
on Oct 08, 1999 at 00:32 UTC ( [id://757]=perlfaq nodetype: print w/replies, xml ) | Need Help?? |
Current Perl documentation can be found at perldoc.perl.org. Here is our local, out-dated (pre-5.6) version:
Use the CGI::Carp module. It replaces warn and die, plus the normal Carp modules
use CGI::Carp; warn "This is a complaint"; die "But this one is serious"; The following use of CGI::Carp also redirects errors to a file of your choice, placed in a BEGIN block to catch compile-time warnings as well:
BEGIN { use CGI::Carp qw(carpout); open(LOG, ">>/var/local/cgi-logs/mycgi-log") or die "Unable to append to mycgi-log: $! "; carpout(*LOG); } You can even arrange for fatal errors to go back to the client browser, which is nice for your own debugging, but might confuse the end user.
use CGI::Carp qw(fatalsToBrowser); die "Bad error here";
Even if the error happens before you get the
HTTP header out, the module will try to take care of
this to avoid the dreaded server 500 errors. Normal warnings still go out
to the server error log (or wherever you've sent them with
|
|