> 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)


In reply to Re: Bizarre Proc::Daemon error # die-handler by LanX
in thread Bizarre Proc::Daemon error by xtpu2

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.