SuppressedError

Limited availability

This feature is not Baseline because it does not work in some of the most widely-used browsers.

The SuppressedError object represents an error generated while handing another error. It is generated during resource disposal using using or await using.

Compared to AggregateError, SuppressedError represents an error that happened during the handling of another error, while AggregateError represents a list of unrelated errors. It is possible, though, for a SuppressedError to contain a chain of suppressed errors (e.suppressed.suppressed.suppressed...). It is also semantically different from cause because the error is not caused by another error, but happens when handling another error.

SuppressedError is a subclass of Error.

Constructor

SuppressedError()

Creates a new SuppressedError object.

Instance properties

Also inherits instance properties from its parent Error.

These properties are defined on SuppressedError.prototype and shared by all SuppressedError instances.

SuppressedError.prototype.constructor

The constructor function that created the instance object. For SuppressedError instances, the initial value is the SuppressedError constructor.

SuppressedError.prototype.name

Represents the name for the type of error. For SuppressedError.prototype.name, the initial value is "SuppressedError".

Note: SuppressedError never has the cause property, because the semantics of cause overlaps with suppressed.

These properties are own properties of each SuppressedError instance.

error

A reference to the error that results in the suppression.

suppressed

A reference to the error that is suppressed by error.

Instance methods

Inherits instance methods from its parent Error.

Examples

Catching a SuppressedError

A SuppressedError is thrown when an error occurs during resource disposal. Throwing an error causes scope cleanup, and each disposer during the cleanup can throw its own error. All these errors are collected into a chain of SuppressedError instances, with the original error as the suppressed property and the new error thrown by the next disposer as the error property.

js
try {
  using resource1 = {
    [Symbol.dispose]() {
      throw new Error("Error while disposing resource1");
    },
  };
  using resource2 = {
    [Symbol.dispose]() {
      throw new Error("Error while disposing resource2");
    },
  };
  throw new Error("Original error");
} catch (e) {
  console.log(e instanceof SuppressedError); // true
  console.log(e.message); // "An error was suppressed during disposal"
  console.log(e.name); // "SuppressedError"
  console.log(e.error); // Error: Error while disposing resource1
  console.log(e.suppressed); // SuppressedError: An error was suppressed during disposal
  console.log(e.suppressed.error); // Error: Error while disposing resource2
  console.log(e.suppressed.suppressed); // Error: Original error
}

The chain looks like this:

       SuppressedError --suppressed--> SuppressedError --suppressed--> Original error
              |                               |
            error                           error
              v                               v
Error while disposing resource1   Error while disposing resource2
    (Disposal happens later)        (Disposal happens earlier)

Creating a SuppressedError

js
try {
  throw new SuppressedError(
    new Error("New error"),
    new Error("Original error"),
    "Hello",
  );
} catch (e) {
  console.log(e instanceof SuppressedError); // true
  console.log(e.message); // "Hello"
  console.log(e.name); // "SuppressedError"
  console.log(e.error); // Error: "New error"
  console.log(e.suppressed); // Error: "Original error"
}

Specifications

Specification
ECMAScript Async Explicit Resource Management
# sec-suppressederror-objects

Browser compatibility

desktop mobile server
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Bun
Deno
Node.js
SuppressedError
Chrome – Full support
Chrome 134 (Release date: 2025-03-04)
footnote Full support
Edge – Full support
Edge 134 (Release date: 2025-03-06)
footnote Full support
Firefox – Full support
Firefox 141 (Release date: 2025-07-22)
footnote Full support
Opera – Full support
Opera 119 (Release date: 2025-05-13)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 134 (Release date: 2025-03-04)
footnote Full support
Firefox for Android – Full support
Firefox for Android 141 (Release date: 2025-07-22)
footnote Full support
Opera Android – Full support
Opera Android 88 (Release date: 2025-03-19)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 29 (Release date: 2025-10-25)
footnote Full support
WebView Android – Full support
WebView Android 134 (Release date: 2025-03-04)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
Bun – Full support
Bun 1.0.23 (Release date: 2024-01-16)
footnote Full support
Deno – No support
Deno
footnote No support
Node.js – No support
Node.js
footnote No support
SuppressedError
Chrome – Full support
Chrome 134 (Release date: 2025-03-04)
footnote Full support
Edge – Full support
Edge 134 (Release date: 2025-03-06)
footnote Full support
Firefox – Full support
Firefox 141 (Release date: 2025-07-22)
footnote Full support
Opera – Full support
Opera 119 (Release date: 2025-05-13)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 134 (Release date: 2025-03-04)
footnote Full support
Firefox for Android – Full support
Firefox for Android 141 (Release date: 2025-07-22)
footnote Full support
Opera Android – Full support
Opera Android 88 (Release date: 2025-03-19)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 29 (Release date: 2025-10-25)
footnote Full support
WebView Android – Full support
WebView Android 134 (Release date: 2025-03-04)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
Bun – Full support
Bun 1.0.23 (Release date: 2024-01-16)
footnote Full support
Deno – No support
Deno
footnote No support
Node.js – No support
Node.js
footnote No support
error
Chrome – Full support
Chrome 134 (Release date: 2025-03-04)
footnote Full support
Edge – Full support
Edge 134 (Release date: 2025-03-06)
footnote Full support
Firefox – Full support
Firefox 141 (Release date: 2025-07-22)
footnote Full support
Opera – Full support
Opera 119 (Release date: 2025-05-13)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 134 (Release date: 2025-03-04)
footnote Full support
Firefox for Android – Full support
Firefox for Android 141 (Release date: 2025-07-22)
footnote Full support
Opera Android – Full support
Opera Android 88 (Release date: 2025-03-19)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 29 (Release date: 2025-10-25)
footnote Full support
WebView Android – Full support
WebView Android 134 (Release date: 2025-03-04)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
Bun – Full support
Bun 1.0.23 (Release date: 2024-01-16)
footnote Full support
Deno – No support
Deno
footnote No support
Node.js – No support
Node.js
footnote No support
suppressed
Chrome – Full support
Chrome 134 (Release date: 2025-03-04)
footnote Full support
Edge – Full support
Edge 134 (Release date: 2025-03-06)
footnote Full support
Firefox – Full support
Firefox 141 (Release date: 2025-07-22)
footnote Full support
Opera – Full support
Opera 119 (Release date: 2025-05-13)
footnote Full support
Safari – No support
Safari
footnote No support
Chrome Android – Full support
Chrome Android 134 (Release date: 2025-03-04)
footnote Full support
Firefox for Android – Full support
Firefox for Android 141 (Release date: 2025-07-22)
footnote Full support
Opera Android – Full support
Opera Android 88 (Release date: 2025-03-19)
footnote Full support
Safari on iOS – No support
Safari on iOS
footnote No support
Samsung Internet – Full support
Samsung Internet 29 (Release date: 2025-10-25)
footnote Full support
WebView Android – Full support
WebView Android 134 (Release date: 2025-03-04)
footnote Full support
WebView on iOS – No support
WebView on iOS
footnote No support
Bun – Full support
Bun 1.0.23 (Release date: 2024-01-16)
footnote Full support
Deno – No support
Deno
footnote No support
Node.js – No support
Node.js
footnote No support

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
No support
No support

See also