How can I get the stack trace for a JavaScript exception in IE 8?

In Internet Explorer 8 and earlier versions, you can use the error object to get the stack trace of a thrown exception. Here’s an example of how you can modify the code to log the stack trace:

resolveWith: function( context, args ) {
if ( !cancelled && !fired && !firing ) {
    firing = 1;
    try {
        while( callbacks[ 0 ] ) {
            callbacks.shift().apply( context, args );
        }
    }
    // We have to add a catch block for
    // IE prior to 8 or else the finally
    // block will never get executed
    catch (e) {
        if (e.stack) {
            console.log(e.stack);
        }
        throw e;
    }
    finally {
        fired = [ context, args ];
        firing = 0;
    }
}
return this;
 }

In the catch block, you check if the stack property exists on the error object. If it does, you log it to the console. If not, you fall back to just rethrowing the exception. This should allow you to see the stack trace in the console when debugging in Visual Studio.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)