Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

forcing eval'd die to ignore global $SIG{__DIE__} handler

by cLive ;-) (Parson)
on Sep 22, 2007 at 20:04 UTC ( #640544=perlquestion: print w/ replies, xml ) Need Help??
cLive ;-) has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to track down a rogue die in a large system that contains a lot of eval'd code. I was going to use a $SIG{__DIE__} handler to collect system state info at die, something like this:
#!/usr/bin/perl use strict; use warnings; # create a die handler - this will have stack trace # and global var dump in RL local $SIG{__DIE__} = sub { print "REAL DIE CAPTURED @_\n"; exit(0); } +; # localize the die handler (works as expected) print "eval die with local __DIE__ sig handler:\n"; eval { local $SIG{__DIE__}; die "OMG - someone killed kenny"; }; if ($@) { print "Eval die captured: $@\n"; } # no local die triggers handler above - expected, but unwanted. print "eval die without local __DIE__ sig handler:\n"; eval { die "OMG - someone killed kenny"; }; if ($@) { print "Eval die captured: $@\n"; } # real die, works as expected when previous case commented out print "REAL die:\n"; die("This is a real error"); print "\nDie failed...\n";

But, as you can see, I would have to find every eval and add in a localized $SIG{__DIE__} to override the newly defined global.

Is there any way I can force all evals to ignore the global handler and carry on as normal? Or am I going about this the wrong way? Perhaps I need to dive back into Carp to see what I'm missing. Hmmmm...

Thoughts anyone?

Comment on forcing eval'd die to ignore global $SIG{__DIE__} handler
Download Code
Re: forcing eval'd die to ignore global $SIG{__DIE__} handler
by ikegami (Pope) on Sep 22, 2007 at 20:39 UTC
    In your handler, don't print and exit if $^S is true.
      Thanks! Damn I knew there was something simple I was missing. Heh.
      quote latest "perldoc perlvar":

      Having to even think about the $^S variable in your exception handlers is simply wrong. $SIG{__DIE__} as currently implemented invites grievous and difficult to track down errors. Avoid it and use an "END{}" or CORE::GLOBAL::die override instead.

      I'm not saying that I support that, quite the contrary, but at least it is worth to know about this sudden perversion of the nature.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://640544]
Approved by shmem
Front-paged by Old_Gray_Bear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (12)
As of 2014-09-30 21:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (384 votes), past polls