Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript Error object

JavaScript Error object

Error object

The Error object provides error information when an error occurs.

Example

In the following example, the try block contains an undefined function "adddlert"; executing it produces an error, and the catch block outputs the error message:

try

{

adddlert

(

"

Welcome

"

)

;

}

catch

(

err

)

{

document

.

getElementById

(

"

demo

"

)

.

innerHTML

=

err

.

name

"


"

err

.

message

;

}

Try it »

For more about JavaScript errors, you can refer to:JavaScript Errors - throw, try and catch


Error object properties

property Description
name Sets or returns an error name.
message Sets or returns an error message (string).

Non-standard Error object properties

Mozilla and Microsoft define the following non-standard Error object properties:

fileName (Mozilla)

lineNumber (Mozilla)

columnNumber (Mozilla)

stack (Mozilla)

description (Microsoft)

number (Microsoft)

The above properties are not recommended, because they are not supported by all browsers.