The SuppressedError() constructor creates SuppressedError objects.
new SuppressedError(error, suppressed)
new SuppressedError(error, suppressed, message)
SuppressedError(error, suppressed)
SuppressedError(error, suppressed, message)Note: SuppressedError() can be called with or without new. Both create a new SuppressedError instance.
errorThe new error that results in the suppression of suppressed.
suppressedThe error that was originally thrown and is now suppressed.
message OptionalAn optional human-readable description of the aggregate error.
Note: SuppressedError() does not accept options like Error() and other subclasses do, because the semantics of cause overlaps with suppressed.
try {
throw new SuppressedError(
new Error("New error"),
new Error("Original error"),
"Hello",
);
} catch (e) {
console.log(e.suppressed); // Error: "Original error"
console.log(e.error); // Error: "New error"
}