类:DOMException


🌐 Class: DOMException

Web IDL DOMException 类。这些错误会由 Node.js 中的 Web 平台 API 抛出,比如 fetch()、<AbortController>、<AbortSignal> 和 Web 流。详情请参见 Globals 页面上的 Class: DOMException。

🌐 The Web IDL DOMException class. These errors are thrown by web-platform APIs in Node.js such as fetch(), <AbortController>, <AbortSignal>, and Web Streams. For details, see also Class: DOMException on the Globals page.

domException.name 属性用于识别异常的类型(例如 'AbortError')。与 Node.js 中的大多数错误不同,domException.code 属性是一个数字,对应于一个 遗留错误代码名称(例如,ABORT_ERR 的 20)。

🌐 The domException.name property identifies the type of the exception (for example, 'AbortError'). Unlike most errors in Node.js, the domException.code property is a number that corresponds to a legacy error code name (for example, 20 for ABORT_ERR).

支持 <AbortSignal>(例如 events.once())的 Node.js 特定 API 会抛出 Node.js AbortError(一个原生的 <errors.Error>,其 name 为 'AbortError',code 为 'ABORT_ERR'),而不是 DOMException。在任何情况下,要识别中止错误,只需检查 err?.name === 'AbortError' 就够了。

🌐 Node.js-specific APIs that support <AbortSignal> (such as events.once()) throw a Node.js AbortError (a native <errors.Error> with name of 'AbortError' and code of 'ABORT_ERR') rather than a DOMException. To identify abort errors in either case, checking err?.name === 'AbortError' is sufficient.

另见 ABORT_ERR。

🌐 See also ABORT_ERR.