import { Exception } from "https://deno.land/x/ayonli_jsext@v0.9.72/error/index.ts";
A generic exception class, which can be used to represent any kind of error.
It's similar to the DOMException
, but for any JavaScript environment.
Examples
Example 1
Example 1
// throw an exception with a name
import { Exception } from "@ayonli/jsext/error";
throw new Exception("The resource cannot be found", "NotFoundError");
Example 2
Example 2
// throw an exception with a code
import { Exception } from "@ayonli/jsext/error";
throw new Exception("The resource cannot be found", 404);
Example 3
Example 3
// rethrow an exception with a cause
import { Exception } from "@ayonli/jsext/error";
try {
throw new Error("Something went wrong");
} catch (error) {
throw new Exception("An error occurred", { cause: error });
}
Constructors
new
Exception(message: string, options: ExceptionOptions)new
Exception(message: string, options?: number | string | ExceptionOptions)