Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

According to the perlvar docs for $SIG{__DIE__}:

Due to an implementation glitch, the $SIG{__DIE__} hook is called even inside an eval(). Do not use this to rewrite a pending exception in $@ , or as a bizarre substitute for overriding CORE::GLOBAL::die() . This strange action at a distance may be fixed in a future release so that $SIG{__DIE__} is only called if your program is about to exit, as was the original intent. Any other use is deprecated.

However, I find this particular behaviour useful. For instance, in my mod_perl application, pretty much all the code is wrapped in an eval which lets me return a nice error page to the user. Because of this glitch, I am able to inflate an uncaught exception into an error object, with attached stacktrace:

#=================================== sub uncaught_error { #=================================== die @_ if ref $_[0] # already an excep +tion object || ! defined $^S; # code is being co +mpiled my ($class) = caller(0); # throw() does the + work of inflating @_ = ( $class, 'Uncaught', join( '', @_ ) ); # an error message + into an exception object goto $class->can('throw') || \&throw; # of the relevant +class } $SIG{__DIE__} = \&uncaught_error;

Once this 'glitch' is fixed, the above code will no longer work (as in it will no longer give me a stack trace from the place where the error occurred) . Is there a better (not-about-to-be-deprecated) way to do this?



UPDATE: Added some comments to the code

In reply to Deprecated use of $SIG{__DIE__} is useful by clinton

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, 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, 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.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (7)
    As of 2018-03-20 08:47 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (248 votes). Check out past polls.