The SuppressedError() constructor creates SuppressedError objects.
Syntax
new SuppressedError(error, suppressed)
new SuppressedError(error, suppressed, message)
SuppressedError(error, suppressed)
SuppressedError(error, suppressed, message)
[!NOTE]
SuppressedError()can be called with or withoutnew. Both create a newSuppressedErrorinstance.
Parameters
error- : The new error that results in the suppression of
suppressed.
- : The new error that results in the suppression of
suppressed- : The error that was originally thrown and is now suppressed.
message- : An optional human-readable description of the aggregate error.
[!NOTE]
SuppressedError()does not acceptoptionslike Error/Error and other subclasses do, because the semantics of Error/cause overlaps withsuppressed.
Examples
Creating a SuppressedError
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"
}
Specifications
Browser compatibility
See also
来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。
