English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

JavaScript Error Reference Manual

Error object

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.

Error object properties

The following table lists the properties of the Error object:

PropertiesDescription
nameSet or return the error name
messageSet or return the error message

Error object methods

The global Error object does not contain its own methods, but it does indeed inherit some methods from the prototype chain.

Error types

JavaScript has seven core error constructor functions:

TypeDescription
EvalErrorCreate an example that represents an error related to the global function eval()
InternalErrorCreate an example that represents an error that occurs when an internal error is triggered in the JavaScript engine
RangeErrorCreate an example that represents an error that occurs when a numeric variable or parameter exceeds its valid range
ReferenceErrorCreate an example that represents an error that occurs when dereferencing an invalid reference
SyntaxErrorCreate an example that represents a syntax error that occurs when parsing code in eval()
TypeErrorCreate an example that represents an error that occurs when the type of a variable or parameter is invalid
URIErrorCreate an example that represents an error that occurs when passing invalid parameters to encodeURI() or decodeURI()

Non-standard Error Object Properties

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.