Export (0) Print
Expand All

stack Property (Error) (JavaScript)

Gets or sets the error stack as a string that contains the stack trace frames.

object.stack

The stack property is set to undefined when the error is constructed, and gets the trace information when the error is raised. If an error is raised multiple times, the stack property is updated each time the error is raised.

Stack frames are displayed in the following format: at FunctionName (<Fully-qualified name/URL>:<line number>:<column number>)

If you create your own Error object and set the stack trace to a value, the value won't be overwritten when the error is thrown.

The stack property does not show inline functions in its frames. It shows only the physical stack.

The following example shows how to get the stack when you're catching an error.

try
    {
        var x = y.name;
    }
catch(e)
    {
        document.write ("Error stack: ")
        document.write (e.stack);
    }

The following example shows how to set and then get the stack.

try
    {
        var err = Error("my error");
        err.stack = "my stack trace";
        throw err;
    }
catch(e)
    {
        document.write ("Error stack: ")
        document.write (e.stack);
    }

Supported in Internet Explorer 10 and in Windows Store apps.

Applies To: Error Object (JavaScript)

Show:
© 2014 Microsoft