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.


In reply to Re: How bad is $SIG{__DIE__} really? by Corion
in thread How bad is $SIG{__DIE__} really? by haukex

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.