DOMException
interface represents an abnormal event (called an
exception
) that 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 名称 , which is a short "CamelCase" style string identifying the error or abnormal condition.
DOMException()
DOMException
object with a specified message and name.
DOMException.code
只读
short
that contains one of the error code constants, or
0
if none match. This field is used for historical reasons. New DOM exceptions don't use this anymore: they put this info in the
DOMException.name
属性。
DOMException.message
只读
DOMString
representing a message or description associated with the given
error name
.
DOMException.name
只读
DOMString
that contains one of the strings associated with an
error name
.
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 that corresponded with a named variable defined to have that value, some of the entries below indicate the legacy code value and constant name that were used in the past.
IndexSizeError
范围
object. (Legacy code value:
1
and legacy constant name:
INDEX_SIZE_ERR
)
HierarchyRequestError
3
and legacy constant name:
HIERARCHY_REQUEST_ERR
)
WrongDocumentError
Document
. (Legacy code value:
4
and legacy constant name:
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
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.
SecurityError
18
and legacy constant name:
SECURITY_ERR
)
NetworkError
19
and legacy constant name:
NETWORK_ERR
)
AbortError
20
and legacy constant name:
ABORT_ERR
)
URLMismatchError
21
and legacy constant name:
URL_MISMATCH_ERR
)
QuotaExceededError
22
and legacy constant name:
QUOTA_EXCEEDED_ERR
)
TimeoutError
23
and legacy constant name:
TIMEOUT_ERR
)
InvalidNodeTypeError
24
and legacy constant name:
INVALID_NODE_TYPE_ERR
)
DataCloneError
25
and legacy constant name:
DATA_CLONE_ERR
)
EncodingError
The encoding or decoding operation failed (No legacy code value and constant name).
NotReadableError
The input/output read operation failed (No legacy code value and constant name).
UnknownError
The operation failed for an unknown transient reason (e.g. out of memory) (No legacy code value and constant name).
ConstraintError
A mutation operation in a transaction failed because a constraint was not satisfied (No legacy code value and constant name).
DataError
Provided data is inadequate (No legacy code value and constant name).
TransactionInactiveError
A request was placed against a transaction that is currently not active or is finished (No legacy code value and constant name).
ReadOnlyError
The mutating operation was attempted in a "readonly" transaction (No legacy code value and constant name).
VersionError
An attempt was made to open a database using a lower version than the existing version (No legacy code value and constant name).
OperationError
The operation failed for an operation-specific reason (No legacy code value and constant name).
NotAllowedError
The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission (No legacy code value and constant name).
| 规范 | 状态 | 注释 |
|---|---|---|
|
Web IDL
The definition of 'constructor' in that specification. |
候选推荐 |
Adds the constructor for the
DOMException
class. Adds the
NotReadableError
,
UnknownError
,
ConstraintError
,
DataError
,
TransactionInactiveError
,
ReadOnlyError
,
VersionError
,
OperationError
,和
NotAllowedError
值。
|
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
DOMException
|
Chrome Yes | Edge ≤18 | Firefox 1 | IE ? | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android 4 | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
DOMException()
构造函数
|
Chrome Yes | Edge 79 | Firefox ? | IE ? | Opera Yes | Safari ? | WebView Android Yes | Chrome Android Yes | Firefox Android ? | Opera Android Yes | Safari iOS ? | Samsung Internet Android Yes |
code
|
Chrome Yes | Edge 12 | Firefox 1 | IE ? | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android 4 | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
message
|
Chrome Yes | Edge 12 | Firefox 1 | IE ? | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android 4 | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
名称
|
Chrome Yes | Edge 12 | Firefox 1 | IE ? | Opera Yes | Safari Yes | WebView Android Yes | Chrome Android Yes | Firefox Android 4 | Opera Android Yes | Safari iOS Yes | Samsung Internet Android Yes |
完整支持
兼容性未知
DOMException
AbortController
AbortSignal
AbstractRange
Attr
ByteString
CDATASection
CSSPrimitiveValue
CSSValue
CSSValueList
CharacterData
ChildNode
注释
CustomEvent
DOMConfiguration
DOMError
DOMErrorHandler
DOMImplementation
DOMImplementationList
DOMImplementationRegistry
DOMImplementationSource
DOMLocator
DOMObject
DOMParser
DOMPoint
DOMPointInit
DOMPointReadOnly
DOMRect
DOMString
DOMTimeStamp
DOMTokenList
DOMUserData
Document
DocumentFragment
DocumentType
元素
ElementTraversal
Entity
EntityReference
事件
EventTarget
HTMLCollection
MutationObserver
节点
NodeFilter
NodeIterator
NodeList
NonDocumentTypeChildNode
ProcessingInstruction
PromiseResolver
范围
StaticRange
文本
TextDecoder
TextEncoder
TimeRanges
TreeWalker
TypeInfo
USVString
UserDataHandler
XMLDocument