Function assertIsError
- assert
Is <E>(error, ErrorClass?, msgMatches?, msg?): asserts error is EError Type Parameters
Parameters
- error: unknown
The error to assert.
OptionalErrorClass: (new (...args: any[]) => E)The optional error class to assert.
OptionalmsgMatches: string | RegExpThe optional string or RegExp to assert in the error message.
Optionalmsg: stringThe optional message to display if the assertion fails.
Returns asserts error is E
Example: Usage
import { assertIsError } from "@std/assert";
assertIsError(null); // Throws
assertIsError(new RangeError("Out of range")); // Doesn't throw
assertIsError(new RangeError("Out of range"), SyntaxError); // Throws
assertIsError(new RangeError("Out of range"), SyntaxError, "Out of range"); // Doesn't throw
assertIsError(new RangeError("Out of range"), SyntaxError, "Within range"); // Throws- error: unknown
Make an assertion that
erroris anError. If not then an error will be thrown. An error class and a string that should be included in the error message can also be asserted.