SuppressedError() constructor
En esta página
The SuppressedError() constructor creates {{jsxref("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. suppressed- : The error that was originally thrown and is now suppressed.
message{{optional_inline}}- : An optional human-readable description of the aggregate error.
[!NOTE]
SuppressedError()does not acceptoptionslike {{jsxref("Error/Error", "Error()")}} and other subclasses do, because the semantics of {{jsxref("Error/cause", "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#
{{Specifications}}
Browser compatibility#
{{Compat}}