XML DOM Tutorial on DOM DOMException Object

the domexception represents an abnormal event happening when a method or a property is used.

properties

below table lists the properties of the domexception object

s.no. property & description
1

name

returns a domstring that contains one of the string associated with an error constant (as seen the table below).

error types

s.no. type & description
1

indexsizeerror

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)

2

hierarchyrequesterror

the node tree hierarchy is not correct. (legacy code value: 3 and legacy constant name: hierarchy_request_err)

3

wrongdocumenterror

the object is in the wrong document. (legacy code value: 4 and legacy constant name: wrong_document_err)

4

invalidcharactererror

the string contains invalid characters. (legacy code value: 5 and legacy constant name: invalid_character_err)

5

nomodificationallowederror

the object cannot be modified. (legacy code value: 7 and legacy constant name: no_modification_allowed_err)

6

notfounderror

the object cannot be found here. (legacy code value: 8 and legacy constant name: not_found_err)

7

notsupportederror

the operation is not supported. (legacy code value: 9 and legacy constant name: not_supported_err)

8

invalidstateerror

the object is in an invalid state. (legacy code value: 11 and legacy constant name: invalid_state_err)

9

syntaxerror

the string did not match the expected pattern. (legacy code value: 12 and legacy constant name: syntax_err)

10

invalidmodificationerror

the object cannot be modified in this way. (legacy code value: 13 and legacy constant name: invalid_modification_err)

11

namespaceerror

the operation is not allowed by namespaces in xml. (legacy code value: 14 and legacy constant name: namespace_err)

12

invalidaccesserror

the object does not support the operation or argument. (legacy code value: 15 and legacy constant name: invalid_access_err)

13

typemismatcherror

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.

14

securityerror

the operation is insecure. (legacy code value: 18 and legacy constant name: security_err)

15

networkerror

a network error occurred. (legacy code value: 19 and legacy constant name: network_err)

16

aborterror

the operation was aborted. (legacy code value: 20 and legacy constant name: abort_err)

17

urlmismatcherror

the given url does not match another url. (legacy code value: 21 and legacy constant name: url_mismatch_err)

18

quotaexceedederror

the quota has been exceeded. (legacy code value: 22 and legacy constant name: quota_exceeded_err)

19

timeouterror

the operation timed out. (legacy code value: 23 and legacy constant name: timeout_err)

20

invalidnodetypeerror

the node is incorrect or has an incorrect ancestor for this operation. (legacy code value: 24 and legacy constant name: invalid_node_type_err)

21

datacloneerror

the object cannot be cloned. (legacy code value: 25 and legacy constant name: data_clone_err)

22

encodingerror

the encoding operation, being an encoding or a decoding one, failed (no legacy code value and constant name).

23

notreadableerror

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.

error.xml contents are as below −

<?xml version = "1.0" encoding = "utf-8" standalone = "no" ?>
<company id = "companyid">
   <employee category = "technical" id = "firstelement" type = "text/html">
      <firstname>tanmay</first>
      <lastname>patil</lastname>
      <contactno>1234567890</contactno>
      <email>tanmaypatil@xyz.com</email>
   </employee>
</company>

following example demonstrates the usage of the name attribute −

<html>
   <head>
      <script>
         function loadxmldoc(filename) {
            if (window.xmlhttprequest) {
               xhttp = new xmlhttprequest();
            } else // code for ie5 and ie6 {
               xhttp = new activexobject("microsoft.xmlhttp");
            }
            xhttp.open("get",filename,false);
            xhttp.send();
            return xhttp.responsexml;
         }
      </script>
   </head>
   <body>
      <script>
         try {
            xmldoc = loadxmldoc("/dom/error.xml");
            var node  = xmldoc.getelementsbytagname("to").item(0);
            var refnode = node.nextsibling;
            var newnode = xmldoc.createtextnode('that is why you fail.');
            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