in reply to How to detect a die() without catching it?


I may be missing something (or a lot) but can't you just call die() with $@ to reproduce the original error message:
eval { &$code; }; # call the wrapped sub if ($@) { # do something about that die $@; } else { # do something else }

--
John.

Replies are listed 'Best First'.
Re: Re: How to detect a die() without catching it?
by samtregar (Abbot) on May 17, 2002 at 23:06 UTC
    The problem is that when that die() gets printed it will say "at Devel::Profiler, line X" instead of the real source of the die().

    -sam

      For this part, you can just add a "\n" to the end of the message, right? e.g.
      sub blah { die "blah"; } eval {blah();}; if ($@) { die "$@\n"; } else { print "okay\n"; } # prints "blah at foo.pl line 4"
      /s
        We have a winner! This will produce exactly the behavior I'm looking for without requiring an explicit stack and nasty %SIG hackery. Thanks!

        -sam