DOMException is the global error type used by Web APIs.
const error = new DOMException(
"input is not valid base64",
"InvalidCharacterError",
);
error.name; // "InvalidCharacterError"
error.message; // "input is not valid base64"
error.code; // 5
error instanceof Error; // trueThe constructor accepts optional message and name strings and must be
called with new. Instances inherit from Error.
Legacy code
code maps legacy names to their historical numeric values. Common examples
include:
| Name | Code |
|---|---|
InvalidCharacterError | 5 |
NotFoundError | 8 |
NotSupportedError | 9 |
InvalidStateError | 11 |
SecurityError | 18 |
NetworkError | 19 |
AbortError | 20 |
QuotaExceededError | 22 |
TimeoutError | 23 |
DataCloneError | 25 |
Unmapped names return 0. Legacy constants such as
DOMException.ABORT_ERR are exposed on the constructor and prototype.
Abort, messaging, Fetch, Web Crypto, encoding, and base64 APIs use
DOMException where their contracts require it.