THE WORLD'S LARGEST WEB DEVELOPER SITE

JavaScript Error Reference


Error Object

The Error object provides error information when an error occurs.

Example

In this example we have written "alert" as "adddlert" to deliberately produce an error.

Return the error name and a description of the error:

try {
    adddlert("Welcome");
}
catch(err) {
    document.getElementById("demo").innerHTML =
    err.name + "<br>" + err.message;
}
Try it Yourself »

For a tutorial about JavaScript Errors, read our JavaScript Error Tutorial.


Error Object Properties

Property Description
name Sets or returns an error name
message Sets or returns an error message (a string)

Non-Standard Error Object Properties

Mozilla and Microsoft defines some non-standard error object properties:

fileName (Mozilla)
lineNumber (Mozilla)
columnNumber (Mozilla)
stack (Mozilla)
description (Microsoft)
number (Microsoft)

Do not use these properties in public web sites. They will not work in all browsers.