2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2024-04-10 02:43:44 +00:00
|
|
|
// This module is browser compatible.
|
2023-12-06 17:13:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Error thrown when an assertion fails.
|
|
|
|
*
|
2024-05-30 02:38:16 +00:00
|
|
|
* @example Usage
|
2024-09-19 23:29:31 +00:00
|
|
|
* ```ts ignore
|
refactor(assert,async,bytes,cli,collections,crypto,csv,data-structures,datetime,dotenv,encoding,expect,fmt,front-matter,fs,html,http,ini,internal,io,json,jsonc,log,media-types,msgpack,net,path,semver,streams,testing,text,toml,ulid,url,uuid,webgpu,yaml): import from `@std/assert` (#5199)
* refactor: import from `@std/assert`
* update
2024-06-30 08:30:10 +00:00
|
|
|
* import { AssertionError } from "@std/assert";
|
2023-12-06 17:13:38 +00:00
|
|
|
*
|
2024-07-29 07:46:15 +00:00
|
|
|
* try {
|
|
|
|
* throw new AssertionError("foo", { cause: "bar" });
|
|
|
|
* } catch (error) {
|
|
|
|
* if (error instanceof AssertionError) {
|
|
|
|
* error.message === "foo"; // true
|
|
|
|
* error.cause === "bar"; // true
|
|
|
|
* }
|
|
|
|
* }
|
2023-12-06 17:13:38 +00:00
|
|
|
* ```
|
|
|
|
*/
|
2023-07-13 07:04:30 +00:00
|
|
|
export class AssertionError extends Error {
|
2024-05-30 02:38:16 +00:00
|
|
|
/** Constructs a new instance.
|
|
|
|
*
|
|
|
|
* @param message The error message.
|
2024-07-30 02:15:52 +00:00
|
|
|
* @param options Additional options. This argument is still unstable. It may change in the future release.
|
2024-05-30 02:38:16 +00:00
|
|
|
*/
|
2024-07-29 07:46:15 +00:00
|
|
|
constructor(message: string, options?: ErrorOptions) {
|
|
|
|
super(message, options);
|
2023-12-06 17:13:38 +00:00
|
|
|
this.name = "AssertionError";
|
2023-07-13 07:04:30 +00:00
|
|
|
}
|
|
|
|
}
|