in reply to Re^2: logging, to include unhandled exceptions
in thread logging, to include unhandled exceptions

According to the man page, your code would propagate the die -- but only if executing an eval. Why not always do it?

Not quite. I propagated the die without further action if executing an eval.

I left up to you what to do when outside of any eval, likely something followed by die or exit.

I don't really see the difference between using $SIG{__DIE__} and overriding CORE::GLOBAL::die, so you might as well use the latter.

BEGIN { *CORE::GLOBAL::die = sub { CORE::die(@_) if $^S; ... }; } BEGIN { *CORE::GLOBAL::warn = sub { ... }; }

We still need to check $^S, so I don't understand the warning perlvar gives.

Anyway, in light of the warning in perlvar, what "difficult to track down" errors am I apt to run into, here?

I don't know.

Replies are listed 'Best First'.
Re^4: logging, to include unhandled exceptions
by klassa (Acolyte) on Sep 02, 2008 at 20:10 UTC
    Ahhhhh. I understand your reasoning for using $^S now. Thanks for the clarification...

    I guess the only remain point of confusion I have is about die itself. perlfunc isn't clear on this, as I read it. When something "blows up" in a script, is die what perl invokes, under the covers? It seems not to be, except when it is (so to speak). Consider this code:

    # $SIG{__DIE__} = sub { print "I died.\n"; exit 0 }; BEGIN { *CORE::GLOBAL::die = sub { print "Died in the new die.\n"; exit 0; }; } print "Requiring something bogus.\n"; require "bogus"; print "Done requiring something bogus.\n";

    When I leave the $SIG line commented out, I do not see "Died in the new die". When I uncomment the $SIG line, however, I do see "I died". That's counter-intuitive, since you wouldn't think that $SIG{__DIE__} would fire in the absence of an actual call to die.

    Anyway, as a result of that, I'm inclined to go with the $SIG approach after all, since it seems to catch this kind of a failure -- which is what I'm trying to accomplish. Thanks again!