English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The Error constructor function creates an error object. An instance of the Error object is thrown when a runtime error occurs.
The error object provides error information when an error occurs.
try { aaalert("Hello world"); } document.getElementById("result").innerHTML = e.name + "<br>" + e.message; }test to see‹/›
You can test on ourInLearn more about errors in the JavaScript exception tutorial.
The following table lists the properties of the Error object:
Properties | Description |
---|---|
name | Set or return the error name |
message | Set or return the error message |
The global Error object does not contain its own methods, but it does indeed inherit some methods from the prototype chain.
JavaScript has seven core error constructor functions:
Type | Description |
---|---|
EvalError | Create an example that represents an error related to the global function eval() |
InternalError | Create an example that represents an error that occurs when an internal error is triggered in the JavaScript engine |
RangeError | Create an example that represents an error that occurs when a numeric variable or parameter exceeds its valid range |
ReferenceError | Create an example that represents an error that occurs when dereferencing an invalid reference |
SyntaxError | Create an example that represents a syntax error that occurs when parsing code in eval() |
TypeError | Create an example that represents an error that occurs when the type of a variable or parameter is invalid |
URIError | Create an example that represents an error that occurs when passing invalid parameters to encodeURI() or decodeURI() |
Microsoft and Mozilla have defined some non-standard error object properties:
fileName (Mozilla)
lineNumber (Mozilla)
columnNumber (Mozilla)
stack (Mozilla)
description (Microsoft)
number (Microsoft)
Do not use these properties, as they may not work in all browsers.