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?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: forcing eval'd die to ignore global $SIG{__DIE__} handler
by ikegami (Patriarch) on Sep 22, 2007 at 20:39 UTC | |
by dk (Chaplain) on Sep 23, 2007 at 18:52 UTC | |
by cLive ;-) (Prior) on Sep 22, 2007 at 20:46 UTC |
Back to
Seekers of Perl Wisdom