in reply to Bizarre Proc::Daemon error
> a) Why is the script dying when executing an expression in an eval? Isn't that the whole point of eval?
Your die handler is called from within the block eval and dies like you told him to do. ( update: or maybe not?)
You might(?)¹ be able to check the caller to avoid dieing in block-eval.
== Updates
=== From perlvar
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.
=== Possible workaround
¹) Indeed! As you can see from this test, does caller(1) tell you if the die appeared within an eval .
So better avoid to die in that case! :)
(But you should check the whole caller-chain till top-level for the string (eval) )
use Carp 'cluck'; $SIG{__DIE__}=sub {cluck "called in '",(caller(1))[3],"'\n\n" }; warn "\n---EVALED FATAL\n"; eval { $x=0/0 } or print ">>> $@"; warn "\n---NORMAL FATAL\n"; $x=0/0;
-->
---EVALED FATAL called in '(eval)' at /tmp/tst.pl line 2 main::__ANON__('Illegal division by zero at /tmp/tst.pl line 6.\x{ +a}') called at /tmp/tst.pl line 6 eval {...} called at /tmp/tst.pl line 6 >>> Illegal division by zero at /tmp/tst.pl line 6. ---NORMAL FATAL called in '' at /tmp/tst.pl line 2 main::__ANON__('Illegal division by zero at /tmp/tst.pl line 10.\x +{a}') called at /tmp/tst.pl line 10 Illegal division by zero at /tmp/tst.pl line 10.
=== "may be fixed in a future release"
Well, I wonder why this was never fixed, if a simple check of caller is sufficient.
Cheers Rolf
(addicted to the Perl Programming Language)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Bizarre Proc::Daemon error # die-handler
by hv (Prior) on Jun 12, 2014 at 08:41 UTC | |
by LanX (Saint) on Jun 12, 2014 at 12:12 UTC |
In Section
Seekers of Perl Wisdom