Exception StackTrace in JavaScript

7 views
Skip to first unread message

George Moschovitis

unread,
Dec 1, 2008, 6:09:29 AM12/1/08
to v8-users
Hello there,

I am wondering if v8 provides a way to extract a StackTrace from a
JavaScript Exception, ie something like:

try {
...
} catch (ex) {
ex.stackTrace();
}


thanks,
George.

Søren Gjesse

unread,
Dec 1, 2008, 8:22:19 AM12/1/08
to v8-u...@googlegroups.com
It is not possible to get a stack trace from a JavaScript exception as in the example below. The reason for this is that it is quite expensive to collect a stack trace each time an exception occur. The stack trace have to be build at the time where the exception occur even though the stack trace most likely will never be used. This will add a performance penalty for using exceptions.

You might be able to use the debugger interface to get the stack traces you need. The V8 debugger interface has the ability to have a debug event listener to be called for each exception (both caught and uncaught) thrown. On the bleeding edge there is also an ability to call a function in the context of the debugger which can be used to collect a stack trace.

Regards,
Søren

George Moschovitis

unread,
Dec 1, 2008, 8:43:33 AM12/1/08
to v8-users
> You might be able to use the debugger interface to get the stack traces you
> need. The V8 debugger interface has the ability to have a debug event
> listener to be called for each exception (both caught and uncaught) thrown.
> On the bleeding edge there is also an ability to call a function in the
> context of the debugger which can be used to collect a stack trace.

Can you point me towards some code that will help me understand your
proposals?

thank you,
George.

--
www.gmosx.com

>
> Regards,
> Søren
>
> On Mon, Dec 1, 2008 at 12:09 PM, George Moschovitis <
>
Reply all
Reply to author
Forward
0 new messages