Warnings and Errors

Apress eBooks · 2006

SummaryIn this chapter, we examined Perl’s errors and warnings, how and when Perl generates them, and how we can control them. Warnings can be enabled either globally or selectively, forced on or off from outside the program, and with the new lexical warnings pragma, limited in scope to just the source file and enclosing block where they are declared.Errors cannot be simply switched off, but we can manage them to some extent with END blocks and the __DIE__ signal pseudo-handler. We can also trap warnings with the __WARN__ signal pseudohandler. Neither mechanism is a true signal, but the semantics are implemented the same way.We looked at the Carp module, which generates more useful information than the core die and warn functions, and the Fatal module, to conveniently wrap functions and subroutines in wrapper routines without needing to go to the trouble of implementing our own error handling code, unless we choose to. We also looked at system errors, the special variables $! and $?, the Errno module, intercepting the exit status before an application exits, and working with the system log on both Unix and Windows platforms.Finally, we looked at handling warnings categories with the warnings pragma and saw how to define our own warnings categories so that we can provide tighter control over when and where warnings are generated from our own code.

Read the paper · More papers on PaperTik