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.
DOMException()
DOMException
object with a specified message and name.DOMException.code
Read only
short
that contains one of the error code constants, or 0
if none match. This field is used for historical reasons. New DOM exceptions don't use this anymore: they put this info in the DOMException.name
attribute.DOMException.message
Read only
DOMString
representing a message or description associated with the given error name.DOMException.name
Read only
DOMString
that contains one of the strings associated with an error name.Common error names are listed here. Some APIs define their own sets of names, so this is not necessarily a complete list.
Note: 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 that were used in the past.
IndexSizeError
Range
object. (Legacy code value: 1
and legacy constant name: INDEX_SIZE_ERR
)HierarchyRequestError
3
and legacy constant name: HIERARCHY_REQUEST_ERR
)WrongDocumentError
Document
. (Legacy code value: 4
and legacy constant name: WRONG_DOCUMENT_ERR
)InvalidCharacterError
5
and legacy constant name: INVALID_CHARACTER_ERR
)NoModificationAllowedError
7
and legacy constant name: NO_MODIFICATION_ALLOWED_ERR
)NotFoundError
8
and legacy constant name: NOT_FOUND_ERR
)NotSupportedError
9
and legacy constant name: NOT_SUPPORTED_ERR
)InvalidStateError
11
and legacy constant name: INVALID_STATE_ERR
)SyntaxError
12
and legacy constant name: SYNTAX_ERR
)InvalidModificationError
13
and legacy constant name: INVALID_MODIFICATION_ERR
)NamespaceError
14
and legacy constant name: NAMESPACE_ERR
)InvalidAccessError
15
and legacy constant name: INVALID_ACCESS_ERR
)TypeMismatchError
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.SecurityError
18
and legacy constant name: SECURITY_ERR
)NetworkError
19
and legacy constant name: NETWORK_ER
R
)AbortError
20
and legacy constant name: ABORT_ERR
)URLMismatchError
21
and legacy constant name: URL_MISMATCH_ERR
)QuotaExceededError
22
and legacy constant name: QUOTA_EXCEEDED_ERR
)TimeoutError
23
and legacy constant name: TIMEOUT_ERR
)InvalidNodeTypeError
24
and legacy constant name: INVALID_NODE_TYPE_ERR
)DataCloneError
25
and legacy constant name: DATA_CLONE_ERR
)EncodingError
NotReadableError
UnknownError
ConstraintError
DataError
TransactionInactiveError
ReadOnlyError
VersionError
OperationError
NotAllowedError
Specification | Status | Comment |
---|---|---|
Web IDL The definition of 'constructor' in that specification. | Candidate Recommendation | Adds the constructor for the DOMException class. Adds the NotReadableError , UnknownError , ConstraintError , DataError , TransactionInactiveError , ReadOnlyError , VersionError , OperationError , and NotAllowedError values. |
DOM4 The definition of 'DOMException' in that specification. | Obsolete | 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. | Obsolete | Added of VALIDATION_ERR and TYPE_MISMATCH_ERR . |
Document Object Model (DOM) Level 2 Core Specification The definition of 'DOMException' in that specification. | Obsolete | Added of INVALID_STATE_ERR , SYNTAX_ERR , INVALID_MODIFICATION_ERR , NAMESPACE_ERR , and INVALID_ACCESS_ERR . |
Document Object Model (DOM) Level 1 Specification The definition of 'DOMException' in that specification. | Obsolete | Initial definition. |
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | 1.0 (1.7 or earlier) | ? | ? | ? |
DOM Level 4 support | (Yes) | ? | 13.0 (13.0) | ? | ? | ? |
DATA_CLONE_ERR constant | (Yes) | (Yes) | 5.0 (5.0) | ? | ? | ? |
Constructor | No support | No support | ? | ? | ? | ? |
Feature | Android | Android Webview | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|---|
Basic support | ? | (Yes) | (Yes) | 1.0 (1.0) | ? | ? | ? | (Yes) |
DOM Level 4 support | ? | (Yes) | ? | 13.0 (13.0) | ? | ? | ? | (Yes) |
DATA_CLONE_ERR constant | ? | (Yes) | (Yes) | 5.0 (5.0) | ? | ? | ? | (Yes) |
Constructor | No support | No support | No support | ? | ? | ? | ? | No support |
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/DOMException