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

x/ayonli_jsext/error/index.ts>Exception

A JavaScript extension package for building strong and modern applications.
Latest
class Exception
extends Error
Re-export
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

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

Properties

optional
cause: unknown
code: number