Chapter 21. Error Handling and Debugging
Every programmer needs to know how to debug his programs. It is an easy task with plain Perl: just invoke the program with the -d flag to invoke the debugger. Under mod_perl, however, you have to jump through a few hoops.
In this chapter we explain how to correctly handle server, program, and user errors and how to keep your user loyal to your service by displaying good error messages.
We also demonstrate how you can peek at what is going on in a
mod_perl-enabled server while it is running: for example, monitoring
the value of a global variable, seeing what database connections are
open, tracing what modules were loaded and their paths, checking the
value of @INC, and much more.
It’s been said that there’s always one more bug in any given program. Bugs that show symptoms during the development cycle are usually easily found. As their number diminishes, the bugs become harder to find. Subtle interactions between software components can create bugs that aren’t easily reproduced. In such cases, tools and techniques that can help track down the offending code come in handy.
Warnings and Errors Explained
The Perl interpreter
distinguishes
between warnings and errors. Warnings are
messages that the Perl interpreter prints to
STDERR (or to Apache’s error log
under mod_perl). These messages indicate that Perl thinks there is a
problem with your code, but they do not prevent the code from
running. Errors are output in the same way as warnings, but the ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access