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

In reply to die hooks, signal handlers and eval, all mixed up by Amoe

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.