Movatterモバイル変換


[0]ホーム

URL:


MDN Web Docs

DOMException: DOMException() constructor

BaselineWidely available

Note: This feature is available inWeb Workers.

TheDOMException() constructor returns aDOMException object with a specified message and name.

Syntax

js
new DOMException()new DOMException(message)new DOMException(message, name)

Parameters

messageOptional

A description of the exception. If not present, the empty string'' is used.

nameOptional

A string. If the specified name is astandard error name, then getting thecode property of theDOMException object will return the code number corresponding to the specified name. If not present, the string'Error' is used.

Return value

A newly createdDOMException object.

Examples

In this example, pressing the button causes a customDOMException to be thrown, which is then caught and the custom error message shown in an alert.

HTML

html
<button>Trigger DOM Exception</button><p></p>

JavaScript

js
const button = document.querySelector("button");button.onclick = () => {  try {    throw new DOMException("Custom DOM Exception Triggered.");  } catch (error) {    document.querySelector("#output").textContent = `Error: ${error.message}`;  }};

Result

Specifications

Specification
Web IDL
# dom-domexception-domexception

Browser compatibility

See also

Help improve MDN

Learn how to contribute.

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp