DOM - DOMException Object
DOM - DOMException Object
Properties
Below table lists the properties of the DOMException object
name
1 Returns a DOMString that contains one of the string associated with an error
constant (as seen the table below).
Error Types
https://www.tutorialspoint.com/dom/dom_domexception_object.htm 1/5
23/10/2021 16:37 DOM - DOMException Object
IndexSizeError
1 The index is not in the allowed range. For example, this can be thrown by the Range
object. (Legacy code value: 1 and legacy constant name: INDEX_SIZE_ERR)
HierarchyRequestError
2 The node tree hierarchy is not correct. (Legacy code value: 3 and legacy constant
name: HIERARCHY_REQUEST_ERR)
WrongDocumentError
3 The object is in the wrong document. (Legacy code value: 4 and legacy constant
name: WRONG_DOCUMENT_ERR)
InvalidCharacterError
4 The string contains invalid characters. (Legacy code value: 5 and legacy constant
name: INVALID_CHARACTER_ERR)
NoModificationAllowedError
5 The object cannot be modified. (Legacy code value: 7 and legacy constant name:
NO_MODIFICATION_ALLOWED_ERR)
NotFoundError
6 The object cannot be found here. (Legacy code value: 8 and legacy constant name:
NOT_FOUND_ERR)
NotSupportedError
7 The operation is not supported. (Legacy code value: 9 and legacy constant name:
NOT_SUPPORTED_ERR)
InvalidStateError
8 The object is in an invalid state. (Legacy code value: 11 and legacy constant name:
INVALID_STATE_ERR)
SyntaxError
9 The string did not match the expected pattern. (Legacy code value: 12 and legacy
constant name: SYNTAX_ERR)
https://www.tutorialspoint.com/dom/dom_domexception_object.htm 2/5
23/10/2021 16:37 DOM - DOMException Object
10 InvalidModificationError
The object cannot be modified in this way. (Legacy code value: 13 and legacy
constant name: INVALID_MODIFICATION_ERR)
NamespaceError
11 The operation is not allowed by Namespaces in XML. (Legacy code value: 14 and
legacy constant name: NAMESPACE_ERR)
InvalidAccessError
12 The object does not support the operation or argument. (Legacy code value: 15 and
legacy constant name: INVALID_ACCESS_ERR)
TypeMismatchError
The type of the object does not match the expected type. (Legacy code value: 17 and
13 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
14 The operation is insecure. (Legacy code value: 18 and legacy constant name:
SECURITY_ERR)
NetworkError
15 A network error occurred. (Legacy code value: 19 and legacy constant name:
NETWORK_ERR)
AbortError
16 The operation was aborted. (Legacy code value: 20 and legacy constant name:
ABORT_ERR)
URLMismatchError
17 The given URL does not match another URL. (Legacy code value: 21 and legacy
constant name: URL_MISMATCH_ERR)
QuotaExceededError
18 The quota has been exceeded. (Legacy code value: 22 and legacy constant name:
QUOTA_EXCEEDED_ERR)
https://www.tutorialspoint.com/dom/dom_domexception_object.htm 3/5
23/10/2021 16:37 DOM - DOMException Object
19 TimeoutError
The operation timed out. (Legacy code value: 23 and legacy constant name:
TIMEOUT_ERR)
InvalidNodeTypeError
20 The node is incorrect or has an incorrect ancestor for this operation. (Legacy code
value: 24 and legacy constant name: INVALID_NODE_TYPE_ERR)
DataCloneError
21 The object cannot be cloned. (Legacy code value: 25 and legacy constant name:
DATA_CLONE_ERR)
EncodingError
22 The encoding operation, being an encoding or a decoding one, failed (No legacy
code value and constant name).
NotReadableError
23
The input/output read operation failed (No legacy code value and constant name).
Example
Following example demonstrates how using a not well-formed XML document causes a
DOMException.
<Company id = "companyid">
<FirstName>Tanmay</first>
<LastName>Patil</LastName>
<ContactNo>1234567890</ContactNo>
<Email>[email protected]</Email>
</Employee>
</Company>
<html>
<head>
<script>
function loadXMLDoc(filename) {
if (window.XMLHttpRequest) {
https://www.tutorialspoint.com/dom/dom_domexception_object.htm 4/5
23/10/2021 16:37 DOM - DOMException Object
xhttp.open("GET",filename,false);
xhttp.send();
return xhttp.responseXML;
</script>
</head>
<body>
<script>
try {
xmlDoc = loadXMLDoc("/dom/error.xml");
node.insertBefore(newnode, refnode);
} catch(err) {
document.write(err.name);
</script>
</body>
</html>
Execution
Save this file as domexcption_name.html on the server path (this file and error.xml should be on
the same path in your server). We will get the output as shown below −
TypeError
https://www.tutorialspoint.com/dom/dom_domexception_object.htm 5/5