{{ APIRef("DOM") }}
The DOMException
exception represents an abnormal event happening when a method or a property is used.
Constructor
- {{domxref("DOMException.DOMException()", "DOMException()")}} {{experimental_inline}}
- Returns a
DOMException
object with a specified message and name.
Attributes
- {{domxref("DOMException.code")}} {{ deprecated_inline() }} {{readOnlyInline}}
- Returns a
short
that contains one of the error code constants, or0
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 {{domxref("DOMException.name")}} attribute. - {{domxref("DOMException.name")}} {{readOnlyInline}}
- Returns a {{domxref("DOMString")}} that contains one of the string associated with an error constant.
Error Constants
- {{exceptionAnchor("IndexSizeError")}}
- The index is not in the allowed range. For example, this can be thrown by {{ domxref("Range") }} object. (Legacy code value:
1
and legacy constant name:INDEX_SIZE_ERR
) - {{exceptionAnchor("HierarchyRequestError")}}
- The node tree hierarchy is not correct. (Legacy code value:
3
and legacy constant name:HIERARCHY_REQUEST_ERR
) - {{exceptionAnchor("WrongDocumentError")}}
- The object is in the wrong {{ domxref("Document") }}. (Legacy code value:
4
and legacy constant name:WRONG_DOCUMENT_ERR
) - {{exceptionAnchor("InvalidCharacterError")}}
- The string contains invalid characters. (Legacy code value:
5
and legacy constant name:INVALID_CHARACTER_ERR
) - {{exceptionAnchor("NoModificationAllowedError")}}
- The object can not be modified. (Legacy code value:
7
and legacy constant name:NO_MODIFICATION_ALLOWED_ERR
) - {{exceptionAnchor("NotFoundError")}}
- The object can not be found here. (Legacy code value:
8
and legacy constant name:NOT_FOUND_ERR
) - {{exceptionAnchor("NotSupportedError")}}
- The operation is not supported. (Legacy code value:
9
and legacy constant name:NOT_SUPPORTED_ERR
) - {{exceptionAnchor("InvalidStateError")}}
- The object is in an invalid state. (Legacy code value:
11
and legacy constant name:INVALID_STATE_ERR
) - {{exceptionAnchor("SyntaxError")}}
- The string did not match the expected pattern. (Legacy code value:
12
and legacy constant name:SYNTAX_ERR
) - {{exceptionAnchor("InvalidModificationError")}}
- The object can not be modified in this way. (Legacy code value:
13
and legacy constant name:INVALID_MODIFICATION_ERR
) - {{exceptionAnchor("NamespaceError")}}
- The operation is not allowed by Namespaces in XML. (Legacy code value:
14
and legacy constant name:NAMESPACE_ERR
) - {{exceptionAnchor("InvalidAccessError")}}
- The object does not support the operation or argument. (Legacy code value:
15
and legacy constant name:INVALID_ACCESS_ERR
) - {{exceptionAnchor("TypeMismatchError")}} {{deprecated_inline}}
- 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 {{jsxref("TypeError")}} exception is now raised instead of aDOMException
with this value. - {{exceptionAnchor("SecurityError")}} {{experimental_inline}}
- The operation is insecure. (Legacy code value:
18
and legacy constant name:SECURITY_ERR
) - {{exceptionAnchor("NetworkError")}} {{experimental_inline}}
- A network error occurred. (Legacy code value:
19
and legacy constant name:NETWORK_ER
R
) - {{exceptionAnchor("AbortError")}} {{experimental_inline}}
- The operation was aborted. (Legacy code value:
20
and legacy constant name:ABORT_ERR
) - {{exceptionAnchor("URLMismatchError")}} {{experimental_inline}}
- The given URL does not match another URL. (Legacy code value:
21
and legacy constant name:URL_MISMATCH_ERR
) - {{exceptionAnchor("QuotaExceededError")}} {{experimental_inline}}
- The quota has been exceeded. (Legacy code value:
22
and legacy constant name:QUOTA_EXCEEDED_ERR
) - {{exceptionAnchor("TimeoutError")}} {{experimental_inline}}
- The operation timed out. (Legacy code value:
23
and legacy constant name:TIMEOUT_ERR
) - {{exceptionAnchor("InvalidNodeTypeError")}} {{experimental_inline}}
- The node is incorrect or has an incorrect ancestor for this operation. (Legacy code value:
24
and legacy constant name:INVALID_NODE_TYPE_ERR
) - {{exceptionAnchor("DataCloneError")}} {{experimental_inline}}
- The object can not be cloned. (Legacy code value:
25
and legacy constant name:DATA_CLONE_ERR
) - {{exceptionAnchor("EncodingError")}} {{experimental_inline}}
- The encoding operation, being an encoding or a decoding one, failed (No legacy code value and constant name).
- {{exceptionAnchor("NotReadableError")}} {{experimental_inline}}
- The input/output read operation failed (No legacy code value and constant name).
Specifications
Specification | Status | Comment |
---|---|---|
{{SpecName('WebIDL', '#es-DOMException-call', 'constructor')}} | {{Spec2('WebIDL')}} | Adds the constructor for the DOMException class. |
{{SpecName('DOM WHATWG', '#exception-domexception', 'DOMException')}} | {{Spec2('DOM WHATWG')}} | Since the latest snapshot, {{SpecName("DOM4")}}, and the NotReadableError value have been added. |
{{SpecName('DOM4', '#exception-domexception', 'DOMException')}} | {{Spec2('DOM4')}} | 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. |
{{SpecName('DOM3 Core', 'core.html#ID-17189187', 'DOMException')}} | {{Spec2('DOM3 Core')}} | Added of VALIDATION_ERR and TYPE_MISMATCH_ERR . |
{{SpecName('DOM2 Core', 'core.html#ID-17189187', 'DOMException')}} | {{Spec2('DOM2 Core')}} | Added of INVALID_STATE_ERR , SYNTAX_ERR , INVALID_MODIFICATION_ERR , NAMESPACE_ERR , and INVALID_ACCESS_ERR . |
{{SpecName('DOM1', 'level-one-core.html#ID-17189187', 'DOMException')}} | {{Spec2('DOM1')}} | Initial definition. |
Browser compatibility
{{ CompatibilityTable() }}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{ CompatVersionUnknown() }} | {{ CompatGeckoDesktop("1.0") }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} |
DOM Level 4 support | {{ CompatVersionUnknown() }} | {{ CompatGeckoDesktop("13.0") }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} |
DATA_CLONE_ERR constant |
{{ CompatVersionUnknown() }} | {{ CompatGeckoDesktop("5.0") }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} |
Constructor | {{CompatNo}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} |
Feature | Android | Android Webview | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile | Chrome for Android |
---|---|---|---|---|---|---|---|
Basic support | {{ CompatUnknown() }} | {{CompatVersionUnknown}} | {{ CompatGeckoMobile("1.0") }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{CompatVersionUnknown}} |
DOM Level 4 support | {{ CompatUnknown() }} | {{CompatVersionUnknown}} | {{ CompatGeckoMobile("13.0") }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{CompatVersionUnknown}} |
DATA_CLONE_ERR constant |
{{ CompatUnknown() }} | {{CompatVersionUnknown}} | {{ CompatGeckoMobile("5.0") }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{ CompatUnknown() }} | {{CompatVersionUnknown}} |
Constructor | {{CompatNo}} | {{CompatNo}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatUnknown}} | {{CompatNo}} |
See also
- {{ domxref("DOMError") }}