Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/error/Exception.ts>default

A JavaScript extension package for building strong and modern applications.
Latest
class default
extends Error
import { default } from "https://deno.land/x/ayonli_jsext@v0.9.72/error/Exception.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

// throw an exception with a name
import { Exception } from "@ayonli/jsext/error";

throw new Exception("The resource cannot be found", "NotFoundError");

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

// 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
default(message: string, name?: string)
new
default(message: string, code?: number)
new
default(message: string, options: ExceptionOptions)
new
default(message: string, options?: number | string | ExceptionOptions)

Properties

optional
cause: unknown
code: number