DOMException

Web API exception class and legacy codes.

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; // true

The 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:

NameCode
InvalidCharacterError5
NotFoundError8
NotSupportedError9
InvalidStateError11
SecurityError18
NetworkError19
AbortError20
QuotaExceededError22
TimeoutError23
DataCloneError25

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.