9.4. Playing Catch-Up

Let's say that you want to go in the other direction and instead of turning errors into exceptions, you want to know when your program is about to die. The brute-force approach is to define a pseudo signal handler for __DIE__:

$SIG{__DIE__} = sub { print "Igor lives!\n" };

but this is rather ineffectual for several reasons. First, we don't know why the program is dying (without parsing the argument, which is an arbitrary string). Second, we don't know where the program is dying without parsing the line number out of the argument (but when you think about it, that information is absolutely useless inside your program). And third, the Faustian bargain that this handler has made lasts only as long as it does; as soon as the ...

Get Perl Debugged now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.