http://www.perlmonks.org?node_id=128708

Amoe has asked for the wisdom of the Perl Monks concerning the following question:

Hey.

I was browsing through the perldocs and saw this thing called $SIG{__DIE__}, which looked quite cool. In my script I had already implemented by redirecting STDERR to a file with magic open, but my one problem with this was that dies got printed to the logfile also, and not to the screen. I wanted them to go to both the screen and the logfile. So I thought, "COOL", and quickly added this line:

$SIG{__DIE__} = sub { print @_; die @_ };

Run it, everything was cool for a while. Then suddenly, alas. My code depends on some modules (the cause seems to be the URI module), and my __DIE__ handler was getting invoked by a module - inside an eval, that's why I never saw it before. die knows not to print it because it's being caught. print doesn't.

My guess is that I'll have to find an alternate way to do this. If so, can anyone suggest one? Or is there some way (hopefully not too magical) that I can find out whether my __DIE__ hook got called from inside an eval? It seems to me that a more effective design for this hook would be to make it not get called at all if it was inside one.

Thanks, Amoe.

--
my one true love