JavaScript Error Object
Error Object
The Error object provides error prompt information when an error occurs.
Examples
In the following example, the try statement block contains an undefined function "adddlert". Executing it will cause an error, and the catch statement block will output the error information:
try {
adddlert("Welcome");
}
catch(err) {
document.getElementById("demo").innerHTML =
err.name + "<br>" + err.message;
}
Try it Yourself »
For more about JavaScript errors, 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)
It is not recommended to use the above properties because not all browsers support them.
Other Extensions