mirror of
https://github.com/denoland/std.git
synced 2024-11-22 04:59:05 +00:00
32 lines
843 B
TypeScript
32 lines
843 B
TypeScript
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
|
// This module is browser compatible.
|
|
|
|
/**
|
|
* Error thrown when an assertion fails.
|
|
*
|
|
* @example Usage
|
|
* ```ts no-eval
|
|
* import { AssertionError } from "@std/assert";
|
|
*
|
|
* try {
|
|
* throw new AssertionError("foo", { cause: "bar" });
|
|
* } catch (error) {
|
|
* if (error instanceof AssertionError) {
|
|
* error.message === "foo"; // true
|
|
* error.cause === "bar"; // true
|
|
* }
|
|
* }
|
|
* ```
|
|
*/
|
|
export class AssertionError extends Error {
|
|
/** Constructs a new instance.
|
|
*
|
|
* @param message The error message.
|
|
* @param options Additional options. This argument is still unstable. It may change in the future release.
|
|
*/
|
|
constructor(message: string, options?: ErrorOptions) {
|
|
super(message, options);
|
|
this.name = "AssertionError";
|
|
}
|
|
}
|