16.22. Turning Signals into Fatal Errors16.22.1. ProblemEND blocks aren't run when your program dies from an uncaught signal. Your program gets such signals, and you'd like your END blocks to have a chance to clean up. 16.22.3. DiscussionUntrapped signals cause your program to die without running END blocks. Although you could manually install signal handlers that call die, this becomes tedious for a lot of signals: $SIG{INT} = $SIG{HUP} = $SIG{PIPE} = $SIG{TERM} = sub { die }; The sigtrap pragma provides a convenient shorthand for installing such handlers: use sigtrap qw(die untrapped normal-signals); The die import tells sigtrap to call die (you can also import stack-trace to install handlers that trigger stack traces). The untrapped import tells sigtrap to install handlers only for signals that don't already have them, so if you handle SIGPIPE yourself, sigtrap won't replace your handler. normal-signals is one of several imports that specify predefined lists of useful signals to trap. The signal lists are given in Table 16-2. Table 16-2. Signal lists
You can combine signal lists: use sigtrap qw(die untrapped normal-signals error-signals); You can even combine different handler types in one import list. Here we use untrapped to specify only the normal signals for which there is not already a handler installed, then use any to revert to sigtrap's default behavior of installing handlers for all signals in the named list: use sigtrap qw( die untrapped normal-signals stack-trace any error-signals ); 16.22.4. See AlsoRecipe 12.7; the documentation for the standard module sigtrap; Recipe 16.15 Copyright © 2003 O'Reilly & Associates. All rights reserved. |
|