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

Re: Bizarre Proc::Daemon error # die-handler

by LanX (Sage)
on Jun 10, 2014 at 03:09 UTC ( #1089378=note: print w/replies, xml ) Need Help??


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 (Parson) on Jun 12, 2014 at 08:41 UTC

    I'm not sure I understand what you're saying here: eval will trap death, even when invoked from a __DIE__ handler:

    % perl -wl local $SIG{__DIE__} = sub { print "in handler (@_)"; die "from handler"; }; eval { die "foo" }; print "eval returned (but knows the error was <$@>)"; __END__ in handler (foo at - line 5. ) eval returned (but knows the error was <from handler at - line 3. >) %

    Hugo

      Strange ...

      ... your snippet runs identically on my machine and I can't reproduce anymore what I saw (!?!)

      Most likely I was wrong about why the OP's program aborts.

      Cheers Rolf

      (addicted to the Perl Programming Language)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1089378]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (3)
As of 2021-10-20 23:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (82 votes). Check out past polls.

    Notices?