in reply to why did i die?

maybe

my $flag=""; local $SIG{__DIE__} = sub { $flag = "implementor wants to terminate"; ... }; eval "$code"; if ( $flag eq ... and so on...

untested

update

die

You can arrange for a callback to be run just before th +e "die" does its deed, by setting the $SIG{__DIE__} hook. The associated handler will be called with the error text a +nd can change the error message, if it sees fit, by calling "d +ie" again. See "$SIG{expr}" in perlvar for details on sett +ing %SIG entries, and "eval BLOCK" for some examples. Although +this feature was to be run only right before your program wa +s to exit, this is not currently the case--the $SIG{__DIE__} + hook is currently called even inside eval()ed blocks/strings!

Cheers Rolf

( addicted to the Perl Programming Language)

Replies are listed 'Best First'.
Re^2: why did i die?
by markov (Scribe) on Apr 02, 2014 at 09:22 UTC

    Tested:

    perl -we 'my $x = 0;eval "local \$SIG{__DIE__} = sub {\$x = 123};4/0"; + print "$x: $@"' 123: Illegal division by zero at (eval 1) line 1.

    The run-time internal error also calls __DIE__.

    Nastier: I do not know what code is ran inside the eval. It may (probably will) install its own __DIE__ handler.

      you could check something like the errno in '$!' to distinguish.

      > I do not know what code is ran inside the eval.

      well then you'll probably also need a block-eval around the string eval.

      Cheers Rolf

      ( addicted to the Perl Programming Language)

        The $! will only be set when the die() is related to a failing operating system call (for instance open()). That does not work in cases like:

        defined $filename or die "no filename given";