Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: Capturing stack trace in eval

by ikegami (Patriarch)
on Oct 07, 2009 at 20:26 UTC ( [id://799809]=note: print w/replies, xml ) Need Help??


in reply to Re: Capturing stack trace in eval
in thread Capturing stack trace in eval

You can override CORE::GLOBAL::die to throw an exception object

Yes, but it wouldn't work for Perl errors such as the one the OP wants to capture, "Can't use an undefined value as a symbol reference".

The only thing overriding CORE::GLOBAL::die won't catch is compile-time parser errors

It won't catch run-time errors or XS errors either. Perl and XS don't call die, a Perl-space function. They call C function croak (not the one from Carp). Therefore, it only catches user-thrown errors.

Replies are listed 'Best First'.
Re^3: Capturing stack trace in eval
by Joost (Canon) on Oct 07, 2009 at 21:31 UTC
    Actually, I might have been mistaken about my SIG{__DIE__} assertion - I mean that using __DIE__ instead of overriding CORE::GLOBAL::die might indeed be the best way of dealing with it.

    As I said I don't have the code with me at the moment - last time I looked at that specific bit of code was a couple of months ago and I switched implementations a few times.

    In any case, the end result turned out that throwing an exception object that encapsulates the stack trace from whatever means you use to intercept the error was the only reasonable way of dealing with the problem when you also have to deal with eval (both versions).

    Update: the way I implemented it, was that the exception object overloaded stringification so that the stack trace is printed if the exception isn't eventually caught.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2024-03-28 19:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found