in reply to How bad is $SIG{__DIE__} really?

Having looked at SIG magic, it's even more horrible, but the real thing on why to avoid $SIG{__DIE__} is when you mix die and eval. If you can live with your $SIG{__DIE__} handler getting called even when the program doesn't actually die, then I think using it to copy the message to some logging/notification is OK.

$SIG{__DIE__} = sub { die "[".gmtime." UTC] (PID $$) FATAL ".shift }; if( !eval { die "Whoops"; 1; }) { print "Error reading config file, using defaults\n"; ... };

Update: Upon reading your node to completion, you already mentioned the case I'm pointing out, sorry.

Outside of that weird/potentially confusing interaction, I simply wouldn't want to put complex logic in a SIG handler because something already went wrong, but again, copying the message to syslog or whatever doesn't seem too bad.

Replies are listed 'Best First'.
Re^2: How bad is $SIG{__DIE__} really?
by haukex (Archbishop) on Oct 26, 2016 at 08:47 UTC

    Hi Corion,

    Update: Upon reading your node to completion, you already mentioned the case I'm pointing out, sorry.

    I didn't add that "P.S." until I added the "Update", so if there was an overlap in the posting times and you didn't see it, then it's me who should be apologizing! :-/

    Regards,
    -- Hauke D