Firefox Tomorrow

javascript class

AggregateError

View on MDN ↗

The AggregateError object represents an error when several errors need to be wrapped in a single error. It is thrown when multiple errors need to be reported by an operation, for example by any(), when all promises passed to it reject.

Compared to SuppressedError, AggregateError represents a list of unrelated errors, while SuppressedError represents an error that happened during the handling of another error.

AggregateError is a subclass of Error.

Constructor

Instance properties

Also inherits instance properties from its parent Error.

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

These properties are own properties of each AggregateError instance.

  • errors
    • : An array representing the errors that were aggregated.

Instance methods

Inherits instance methods from its parent Error.

Examples

Catching an AggregateError

Promise.any([Promise.reject(new Error("some error"))]).catch((e) => {
  console.log(e instanceof AggregateError); // true
  console.log(e.message); // "All Promises rejected"
  console.log(e.name); // "AggregateError"
  console.log(e.errors); // [ Error: "some error" ]
});

Creating an AggregateError

try {
  throw new AggregateError([new Error("some error")], "Hello");
} catch (e) {
  console.log(e instanceof AggregateError); // true
  console.log(e.message); // "Hello"
  console.log(e.name); // "AggregateError"
  console.log(e.errors); // [ Error: "some error" ]
}

Specifications

SpecificationsStandards references are available on the canonical MDN page.

Browser compatibility

Browser compatibilityCompatibility data is available on the canonical MDN page.

See also