use sigtrap;
use sigtrap qw(stack–trace old–interface–signals);  # same thing

use sigtrap qw(BUS SEGV PIPE ABRT);
use sigtrap qw(die INT QUIT);
use sigtrap qw(die normal–signals);
use sigtrap qw(die untrapped normal–signals);
use sigtrap qw(die untrapped normal–signals
                stack–trace any error–signals);

use sigtrap "handler" => \&my_handler, "normal–signals";
use sigtrap qw(handler my_handler normal–signals stack–trace error–signals);

The sigtrap pragma installs some simple signal handlers on your behalf so that you don’t have to worry about them. This is useful in situations where an untrapped signal would cause your program to misbehave, like when you have END {} blocks, object destructors, or other at-exit processing that needs to be run no matter how your program happens to terminate.

When your program dies of an uncaught signal, the program exits immediately without cleanup. If instead you catch and convert such signals into fatal exceptions, good things happen: all scopes are exited, their resources are relinquished, and any END blocks are processed.

The sigtrap pragma provides two simple signal handlers for your use. One gives a Perl stack trace, and the other throws an exception via die. Alternately, you can supply your own handler for the pragma to install. You may specify predefined sets of signals to trap; you can also supply your own explicit list of signals. The pragma can optionally install handlers for only those signals that have not been otherwise handled.

Arguments ...

Get Programming Perl, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.