JS Errors


Error object

The Error object provides information about the error when the error occurs.

Example

In the following example, the try block contains the undefined function "addddlert", and executing it will generate an error, and the catch block will output the error message:

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

Try It! 

For more JavaScript errors, please refer to: JavaScript Errors - throw, try and catch


Error object properties

PropertyDescription
nameSet or return an error name
messageset or return 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 not all browsers support it.