Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1068018 of DOMException

  • Revision slug: Web/API/DOMException
  • Revision title: DOMException
  • Revision id: 1068018
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment Fix some grammar, add some details

Revision Content

{{ APIRef("DOM") }}

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.

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 {{anch("Error codes", "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 {{domxref("DOMException.name")}} attribute.
{{domxref("DOMException.name")}} {{readOnlyInline}}
Returns a {{domxref("DOMString")}} that contains one of the string 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.

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)
HierarchyRequestError
The node tree hierarchy is not correct. (Legacy code value: 3 and legacy constant name: HIERARCHY_REQUEST_ERR)
WrongDocumentError
The object is in the wrong {{ domxref("Document") }}. (Legacy code value: 4 and legacy constant name: WRONG_DOCUMENT_ERR)
InvalidCharacterError
The string contains invalid characters. (Legacy code value: 5 and legacy constant name: INVALID_CHARACTER_ERR)
NoModificationAllowedError
The object can not be modified. (Legacy code value: 7 and legacy constant name: NO_MODIFICATION_ALLOWED_ERR)
NotFoundError
The object can not be found here. (Legacy code value: 8 and legacy constant name: NOT_FOUND_ERR)
NotSupportedError
The operation is not supported. (Legacy code value: 9 and legacy constant name: NOT_SUPPORTED_ERR)
InvalidStateError
The object is in an invalid state. (Legacy code value: 11 and legacy constant name: INVALID_STATE_ERR)
SyntaxError
The string did not match the expected pattern. (Legacy code value: 12 and legacy constant name: SYNTAX_ERR)
InvalidModificationError
The object can not be modified in this way. (Legacy code value: 13 and legacy constant name: INVALID_MODIFICATION_ERR)
NamespaceError
The operation is not allowed by Namespaces in XML. (Legacy code value: 14 and legacy constant name: NAMESPACE_ERR)
InvalidAccessError
The object does not support the operation or argument. (Legacy code value: 15 and legacy constant name: INVALID_ACCESS_ERR)
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 a DOMException with this value.
SecurityError {{experimental_inline}}
The operation is insecure. (Legacy code value: 18 and legacy constant name: SECURITY_ERR)
NetworkError {{experimental_inline}}
A network error occurred. (Legacy code value: 19 and legacy constant name: NETWORK_ERR)
AbortError {{experimental_inline}}
The operation was aborted. (Legacy code value: 20 and legacy constant name: ABORT_ERR)
URLMismatchError {{experimental_inline}}
The given URL does not match another URL. (Legacy code value: 21 and legacy constant name: URL_MISMATCH_ERR)
QuotaExceededError {{experimental_inline}}
The quota has been exceeded. (Legacy code value: 22 and legacy constant name: QUOTA_EXCEEDED_ERR)
TimeoutError {{experimental_inline}}
The operation timed out. (Legacy code value: 23 and legacy constant name: TIMEOUT_ERR)
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)
DataCloneError {{experimental_inline}}
The object can not be cloned. (Legacy code value: 25 and legacy constant name: DATA_CLONE_ERR)
EncodingError {{experimental_inline}}
The encoding operation, being an encoding or a decoding one, failed (No legacy code value and constant name).
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. Adds the NotReadableError value.
{{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") }}

Revision Source

<p>{{ APIRef("DOM") }}</p>

<p>The <code><strong>DOMException</strong></code> interface represents an abnormal event (called an <strong>exception</strong>) 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.</p>

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

<h2 id="Constructor">Constructor</h2>

<dl>
 <dt>{{domxref("DOMException.DOMException()", "DOMException()")}} {{experimental_inline}}</dt>
 <dd>Returns a <code>DOMException</code> object with a specified message and name.</dd>
</dl>

<h2 id="Attributes">Attributes</h2>

<dl>
 <dt>{{domxref("DOMException.code")}} {{deprecated_inline}} {{readOnlyInline}}</dt>
 <dd>Returns a <code>short</code> that contains one of the {{anch("Error codes", "error code constants")}}, or <code>0</code> 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.</dd>
 <dt>{{domxref("DOMException.name")}} {{readOnlyInline}}</dt>
 <dd>Returns a {{domxref("DOMString")}} that contains one of the string associated with an <a href="#Error_names">error name</a>.</dd>
</dl>

<h2 id="Error_names">Error names</h2>

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

<div class="note">
<p>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.</p>
</div>

<dl>
 <dt><a id="exception-IndexSizeError" name="exception-IndexSizeError"><code>IndexSizeError</code></a></dt>
 <dd>The index is not in the allowed range. For example, this can be thrown by {{ domxref("Range") }} object. (Legacy code value: <code>1</code> and legacy constant name: <code>INDEX_SIZE_ERR</code>)</dd>
 <dt><code><a id="exception-HierarchyRequestError" name="exception-HierarchyRequestError">HierarchyRequestError</a></code></dt>
 <dd>The node tree hierarchy is not correct. (Legacy code value: <code>3</code> and legacy constant name: <code>HIERARCHY_REQUEST_ERR</code>)</dd>
 <dt><a id="exception-WrongDocumentError" name="exception-WrongDocumentError"><code>WrongDocumentError</code></a></dt>
 <dd>The object is in the wrong {{ domxref("Document") }}. (Legacy code value: <code>4</code> and legacy constant name: <code>WRONG_DOCUMENT_ERR</code>)</dd>
 <dt><a id="exception-InvalidCharacterError" name="exception-InvalidCharacterError"><code>InvalidCharacterError</code></a></dt>
 <dd>The string contains invalid characters. (Legacy code value: <code>5</code> and legacy constant name: <code>INVALID_CHARACTER_ERR</code>)</dd>
 <dt><a id="exception-NoModificationAllowedError" name="exception-NoModificationAllowedError"><code>NoModificationAllowedError</code></a></dt>
 <dd>The object can not be modified. (Legacy code value: <code>7</code> and legacy constant name: <code>NO_MODIFICATION_ALLOWED_ERR</code>)</dd>
 <dt><a id="exception-NotFoundError" name="exception-NotFoundError"><code>NotFoundError</code></a></dt>
 <dd>The object can not be found here. (Legacy code value: <code>8</code> and legacy constant name: <code>NOT_FOUND_ERR</code>)</dd>
 <dt><a id="exception-NotFoundError" name="exception-NotFoundError"><code>NotSupportedError</code></a></dt>
 <dd>The operation is not supported. (Legacy code value: <code>9</code> and legacy constant name: <code>NOT_SUPPORTED_ERR</code>)</dd>
 <dt><a id="exception-InvalidStateError" name="exception-InvalidStateError"><code>InvalidStateError</code></a></dt>
 <dd>The object is in an invalid state. (Legacy code value: <code>11</code> and legacy constant name: <code>INVALID_STATE_ERR</code>)</dd>
 <dt><a id="exception-SyntaxError" name="exception-SyntaxError"><code>SyntaxError</code></a></dt>
 <dd>The string did not match the expected pattern. (Legacy code value: <code>12</code> and legacy constant name: <code>SYNTAX_ERR</code>)</dd>
 <dt><a id="exception-InvalidModificationError" name="exception-InvalidModificationError"><code>InvalidModificationError</code></a></dt>
 <dd>The object can not be modified in this way. (Legacy code value: <code>13</code> and legacy constant name: <code>INVALID_MODIFICATION_ERR</code>)</dd>
 <dt><a id="exception-NamespaceError" name="exception-NamespaceError"><code>NamespaceError</code></a></dt>
 <dd>The operation is not allowed by Namespaces in XML. (Legacy code value: <code>14</code> and legacy constant name: <code>NAMESPACE_ERR</code>)</dd>
 <dt><a id="exception-InvalidAccessError" name="exception-InvalidAccessError"><code>InvalidAccessError</code></a></dt>
 <dd>The object does not support the operation or argument. (Legacy code value: <code>15</code> and legacy constant name: <code>INVALID_ACCESS_ERR</code>)</dd>
 <dt><a id="exception-TypeMismatchError" name="exception-TypeMismatchError"><code>TypeMismatchError</code></a> {{deprecated_inline}}</dt>
 <dd>The type of the object does not match the expected type. (Legacy code value: <code>17</code> and legacy constant name: <code>TYPE_MISMATCH_ERR</code>) This value is deprecated, the JavaScript {{jsxref("TypeError")}} exception is now raised instead of a <code>DOMException</code> with this value.</dd>
 <dt><a id="exception-SecurityError" name="exception-SecurityError"><code>SecurityError</code></a> {{experimental_inline}}</dt>
 <dd>The operation is insecure. (Legacy code value: <code>18</code> and legacy constant name: <code>SECURITY_ERR</code>)</dd>
 <dt><a id="exception-NetworkError" name="exception-NetworkError"><code>NetworkError</code></a> {{experimental_inline}}</dt>
 <dd>A network error occurred. (Legacy code value: <code>19</code> and legacy constant name: <code>NETWORK_ER</code><code>R</code>)</dd>
 <dt><a id="exception-AbortError" name="exception-AbortError"><code>AbortError</code></a> {{experimental_inline}}</dt>
 <dd>The operation was aborted. (Legacy code value: <code>20</code> and legacy constant name: <code>ABORT_ERR</code>)</dd>
 <dt><a id="exception-URLMismatchError" name="exception-URLMismatchError"><code>URLMismatchError</code></a> {{experimental_inline}}</dt>
 <dd>The given URL does not match another URL. (Legacy code value: <code>21</code> and legacy constant name: <code>URL_MISMATCH_ERR</code>)</dd>
 <dt><a id="exception-QuotaExceededError" name="exception-QuotaExceededError"><code>QuotaExceededError</code></a> {{experimental_inline}}</dt>
 <dd>The quota has been exceeded. (Legacy code value: <code>22</code> and legacy constant name: <code>QUOTA_EXCEEDED_ERR</code>)</dd>
 <dt><a id="exception-TimeoutError" name="exception-TimeoutError"><code>TimeoutError</code></a> {{experimental_inline}}</dt>
 <dd>The operation timed out. (Legacy code value: <code>23</code> and legacy constant name: <code>TIMEOUT_ERR</code>)</dd>
 <dt><a id="exception-InvalidNodeTypeError" name="exception-InvalidNodeTypeError"><code>InvalidNodeTypeError</code></a> {{experimental_inline}}</dt>
 <dd>The node is incorrect or has an incorrect ancestor for this operation. (Legacy code value: <code>24</code> and legacy constant name: <code>INVALID_NODE_TYPE_ERR</code>)</dd>
 <dt><a id="exception-DataCloneError" name="exception-DataCloneError"><code>DataCloneError</code></a> {{experimental_inline}}</dt>
 <dd>The object can not be cloned. (Legacy code value: <code>25</code> and legacy constant name: <code>DATA_CLONE_ERR</code>)</dd>
 <dt><a id="exception-EncodingError" name="exception-EncodingError"><code>EncodingError</code></a> {{experimental_inline}}</dt>
 <dd>The encoding operation, being an encoding or a decoding one, failed (No legacy code value and constant name).</dd>
 <dt><a id="exception-NotReadableError" name="exception-NotReadableError"><code>NotReadableError</code></a> {{experimental_inline}}</dt>
 <dd>The input/output read operation failed (No legacy code value and constant name).</dd>
</dl>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('WebIDL', '#es-DOMException-call', 'constructor')}}</td>
   <td>{{Spec2('WebIDL')}}</td>
   <td>Adds the constructor for the <code>DOMException</code> class. Adds the <code>NotReadableError</code> value.</td>
  </tr>
  <tr>
   <td>{{SpecName('DOM4', '#exception-domexception', 'DOMException')}}</td>
   <td>{{Spec2('DOM4')}}</td>
   <td>Added <code>SECURITY_ERR</code>, <code>NETWORK_ERR</code>, <code>ABORT_ERR</code>, <code>URL_MISMATCH_ERR</code>, <code>QUOTA_EXCEEDED_ERR</code>, <code>TIMEOUT_ERR</code>, <code>INVALID_NODE_TYPE_ERR</code>, and <code>DATA_CLONE_ERR</code>. The property <code>code</code> has been deprecated for exception values. The <code>EncodingError</code> value added.</td>
  </tr>
  <tr>
   <td>{{SpecName('DOM3 Core', 'core.html#ID-17189187', 'DOMException')}}</td>
   <td>{{Spec2('DOM3 Core')}}</td>
   <td>Added of <code>VALIDATION_ERR</code> and <code>TYPE_MISMATCH_ERR</code>.</td>
  </tr>
  <tr>
   <td>{{SpecName('DOM2 Core', 'core.html#ID-17189187', 'DOMException')}}</td>
   <td>{{Spec2('DOM2 Core')}}</td>
   <td>Added of <code>INVALID_STATE_ERR</code>, <code>SYNTAX_ERR</code>, <code>INVALID_MODIFICATION_ERR</code>, <code>NAMESPACE_ERR</code>, and <code>INVALID_ACCESS_ERR</code>.</td>
  </tr>
  <tr>
   <td>{{SpecName('DOM1', 'level-one-core.html#ID-17189187', 'DOMException')}}</td>
   <td>{{Spec2('DOM1')}}</td>
   <td>Initial definition.</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{ CompatGeckoDesktop("1.0") }}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td>DOM Level 4 support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{ CompatGeckoDesktop("13.0") }}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>DATA_CLONE_ERR</code> constant</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{ CompatGeckoDesktop("5.0") }}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td>Constructor</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Android Webview</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
   <th>Chrome for Android</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{ CompatGeckoMobile("1.0") }}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td>DOM Level 4 support</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{ CompatGeckoMobile("13.0") }}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td><code>DATA_CLONE_ERR</code> constant</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{ CompatGeckoMobile("5.0") }}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
  <tr>
   <td>Constructor</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatNo}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{ domxref("DOMError") }}</li>
</ul>
Revert to this revision