The DOMException interface represents an abnormal event (called an exception) which occurs as a result of calling a method or accessing a property of a web API. This is basically how error conditions are described in web APIs.

Each exception has a name, which is a short "CamelCase" style string identifying the error or abnormal condition.


Returns a DOMException object with a specified message and name.


DOMException.code Read only
Returns a short that contains one of the error code constants, or 0 if none match. This field is used for historical reasons, new kind of DOM exceptions don't use anymore: they put this info in the attribute. Read only
Returns a DOMString that contains one of the strings associated with an error name.

Error names

Common error names are listed here. Some APIs define their own sets of names, so this is not necessarily a complete list.

Because historically the errors were identified by a numeric value which corresponded with a named variable defined to have that value, some of the entries below indicate the legacy code value and constant name which were used in the past.

The index is not in the allowed range. For example, this can be thrown by Range object. (Legacy code value: 1 and legacy constant name: INDEX_SIZE_ERR)
The node tree hierarchy is not correct. (Legacy code value: 3 and legacy constant name: HIERARCHY_REQUEST_ERR)
The object is in the wrong Document. (Legacy code value: 4 and legacy constant name: WRONG_DOCUMENT_ERR)
The string contains invalid characters. (Legacy code value: 5 and legacy constant name: INVALID_CHARACTER_ERR)
The object can not be modified. (Legacy code value: 7 and legacy constant name: NO_MODIFICATION_ALLOWED_ERR)
The object can not be found here. (Legacy code value: 8 and legacy constant name: NOT_FOUND_ERR)
The operation is not supported. (Legacy code value: 9 and legacy constant name: NOT_SUPPORTED_ERR)
The object is in an invalid state. (Legacy code value: 11 and legacy constant name: INVALID_STATE_ERR)
The string did not match the expected pattern. (Legacy code value: 12 and legacy constant name: SYNTAX_ERR)
The object can not be modified in this way. (Legacy code value: 13 and legacy constant name: INVALID_MODIFICATION_ERR)
The operation is not allowed by Namespaces in XML. (Legacy code value: 14 and legacy constant name: NAMESPACE_ERR)
The object does not support the operation or argument. (Legacy code value: 15 and legacy constant name: INVALID_ACCESS_ERR)
The type of the object does not match the expected type. (Legacy code value: 17 and legacy constant name: TYPE_MISMATCH_ERR) This value is deprecated, the JavaScript TypeError exception is now raised instead of a DOMException with this value.
The operation is insecure. (Legacy code value: 18 and legacy constant name: SECURITY_ERR)
A network error occurred. (Legacy code value: 19 and legacy constant name: NETWORK_ERR)
The operation was aborted. (Legacy code value: 20 and legacy constant name: ABORT_ERR)
The given URL does not match another URL. (Legacy code value: 21 and legacy constant name: URL_MISMATCH_ERR)
The quota has been exceeded. (Legacy code value: 22 and legacy constant name: QUOTA_EXCEEDED_ERR)
The operation timed out. (Legacy code value: 23 and legacy constant name: TIMEOUT_ERR)
The node is incorrect or has an incorrect ancestor for this operation. (Legacy code value: 24 and legacy constant name: INVALID_NODE_TYPE_ERR)
The object can not be cloned. (Legacy code value: 25 and legacy constant name: DATA_CLONE_ERR)
The encoding operation, being an encoding or a decoding one, failed (No legacy code value and constant name).
The input/output read operation failed (No legacy code value and constant name).


Specification Status Comment
Web IDL (Second Edition)
The definition of 'constructor' in that specification.
Candidate Recommendation Adds the constructor for the DOMException class. Adds the NotReadableError value.
The definition of 'DOMException' in that specification.
Recommendation Added SECURITY_ERR, NETWORK_ERR, ABORT_ERR, URL_MISMATCH_ERR, QUOTA_EXCEEDED_ERR, TIMEOUT_ERR, INVALID_NODE_TYPE_ERR, and DATA_CLONE_ERR. The property code has been deprecated for exception values. The EncodingError value added.
Document Object Model (DOM) Level 3 Core Specification
The definition of 'DOMException' in that specification.
Recommendation Added of VALIDATION_ERR and TYPE_MISMATCH_ERR.
Document Object Model (DOM) Level 2 Core Specification
The definition of 'DOMException' in that specification.
Document Object Model (DOM) Level 1 Specification
The definition of 'DOMException' in that specification.
Recommendation Initial definition.

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support (Yes) 1.0 (1.7 or earlier) ? ? ?
DOM Level 4 support (Yes) 13.0 (13.0) ? ? ?
DATA_CLONE_ERR constant (Yes) 5.0 (5.0) ? ? ?
Constructor No support ? ? ? ?
Feature Android Android Webview Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile Chrome for Android
Basic support ? (Yes) 1.0 (1.0) ? ? ? (Yes)
DOM Level 4 support ? (Yes) 13.0 (13.0) ? ? ? (Yes)
DATA_CLONE_ERR constant ? (Yes) 5.0 (5.0) ? ? ? (Yes)
Constructor No support No support ? ? ? ? No support

See also

Document Tags and Contributors

 Last updated by: Sheppy,