hugomg
hugomg

Reputation: 69944

Is there a way to get line numbers or stack traces from an Error object in Internet Explorer?

In order to ease debugging some tricky async Javascript code that is misbehaving in Internet Explorer, I want to know if it is possible to, given an Error object, get useful information about its original location.

Firefox, Chrome, Opera and I guess all the other nice browsers all let me do it:

try{
    throw Error('My custom error message');
}catch(e){
    console.log(e.stack)
}

but none of the properties I tried (error.stack and error.lineNumber) work on Internet Explorer. Is there a way to get at this information on Internet Explorer, using Javascript only? Since the IE REPL will show the original line number for unhandled exceptions even if they were caught and rethrown in a different line, I assume the information I want is being stored somewhere, but I could not find out if there is a public way to get at it.

Upvotes: 2

Views: 537

Answers (1)

Dan
Dan

Reputation: 1012

These properties aren't available in IE. You can get some of the way by using the arguments.callee graph. However, this method doesn't work too well if you have a lot of anonymous functions or use bind() frequently.

See goog.debug.getStacktrace() in the Closure Library's debug package for a sample implementation. goog.debug.normalizeErrorObject() may also be useful to you.

Upvotes: 2

Related Questions