AssertError
Defined in: errors.ts:21
The Error subclass thrown by assertNotNull. Its name is
"AssertError", so you can tell a failed assertion apart from other failures
with instanceof (or by error.name). Throw it from your own checks too.
Examples
Section titled “Examples”Tell a failed assertion apart from other errors
import { AssertError, assertNotNull, tryCatch } from "@xtandard/lib";
const [, error] = tryCatch(() => assertNotNull(null));
error instanceof AssertError; // trueString(error); // "AssertError: unexpected null or undefined"Throw it from your own check
if (rows.length === 0) throw new AssertError("expected at least one row");Extends
Section titled “Extends”Error
Constructors
Section titled “Constructors”Constructor
Section titled “Constructor”new AssertError(message?): AssertError;Defined in: errors.ts:34
Creates an assertion error with the given message.
Parameters
Section titled “Parameters”| Parameter | Type | Default value | Description |
|---|---|---|---|
message? |
string |
"unexpected null or undefined" |
The error message. Defaults to "unexpected null or undefined", the same default as assertNotNull. |
Returns
Section titled “Returns”AssertError
Example
Section titled “Example”new AssertError().message; // "unexpected null or undefined"new AssertError("expected at least one row").name; // "AssertError"Overrides
Section titled “Overrides”Error.constructor