--- title: DOMException slug: Web/API/DOMException translation_of: Web/API/DOMException ---
{{ APIRef("DOM") }}
DOMException
接口代表调用方法或访问 Web API 属性时发生的异常事件(被称为异常,exception)。 这基本上是在 Web API 中如何描述错误情况的
每个异常都有一个名称 name,一个采用骆驼式命名法的简短字符串,用于描述识别错误或异常情况。
译者注:骆驼式命名法(CamelCase style),又称驼峰命名法。与 JavaScript 中更常见的小驼峰命名法有别,此处应是指大驼峰命名法。大驼峰命名法又称 Pascal 命名法。具体为名称中的每个单词仅首字母大写(Capitalize),可参考下方错误名称。
DOMException
对象。short
,包含 {{anch("Error codes", "error code constants")}} 中的一个,或者返回 0
,如果没有匹配的话。这个字段由于历史原因被使用。现在不再使用这个新的DOM异常:他们把这个信息放入 {{domxref("DOMException.name")}} 属性。常见的错误名称列在这里。一些 API 定义了它们自己的名称组,所以这未必是一个完整的列表。
注意:因为很久以前错误是由数值(code value,代码值)与一个对应的命名变量定义的,所以以下部分条目包含过去使用的遗留代码值和常量名。
IndexSizeError
1
,遗留常数名称:INDEX_SIZE_ERR
)HierarchyRequestError
3
,遗留常数名称:HIERARCHY_REQUEST_ERR
)WrongDocumentError
4
,遗留常数名称: 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
{{deprecated_inline}}17
and legacy constant name: TYPE_MISMATCH_ERR
) 这个值已被弃用, JavaScript {{jsxref("TypeError")}} 异常被提出而不是DOMException
SecurityError
{{experimental_inline}}18
and legacy constant name: SECURITY_ERR
)NetworkError
{{experimental_inline}}19
and legacy constant name: NETWORK_ER
R
)AbortError
{{experimental_inline}}20
and legacy constant name: ABORT_ERR
)URLMismatchError
{{experimental_inline}}21
and legacy constant name: URL_MISMATCH_ERR
)QuotaExceededError
{{experimental_inline}}22
and legacy constant name: QUOTA_EXCEEDED_ERR
)TimeoutError
{{experimental_inline}}23
and legacy constant name: TIMEOUT_ERR
)InvalidNodeTypeError
{{experimental_inline}}24
and legacy constant name: INVALID_NODE_TYPE_ERR
)sDataCloneError
{{experimental_inline}}25
and legacy constant name: DATA_CLONE_ERR
)EncodingError
{{experimental_inline}}NotReadableError
{{experimental_inline}}UnknownError
{{experimental_inline}}ConstraintError
{{experimental_inline}}DataError
{{experimental_inline}}TransactionInactiveError
{{experimental_inline}}ReadOnlyError
{{experimental_inline}}VersionError
{{experimental_inline}}OperationError
{{experimental_inline}}NotAllowedError
{{experimental_inline}}规范 | 状态 | 备注 |
---|---|---|
{{SpecName('WebIDL', '#idl-DOMException', 'constructor')}} | {{Spec2('WebIDL')}} | Adds the constructor for the DOMException class. Adds the NotReadableError , UnknownError , ConstraintError , DataError , TransactionInactiveError , ReadOnlyError , VersionError , OperationError , and NotAllowedError values. |
{{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. |
{{Compat("api.DOMException")}}