@mfederczuk/custom-exception

Custom Exception class


Keywords
exception, error, custom-exception, javascript, javascript-library, js, ts, typescript, typescript-library
License
CNRI-Python-GPL-Compatible
Install
npm install @mfederczuk/custom-exception@1.1.0

Documentation

Custom JavaScript Exception

version: 1.1.0 Changelog

About

A custom JavaScript exception class.

Download

Using npm:

npm i @mfederczuk/custom-js-exception

Using Yarn:

yarn add @mfederczuk/custom-js-exception

Usage

Just extend the Exception class and call the super constructor from yours.
It's a good idea to have an optional cause parameter that you pass to the super constructor call as well.

import Exception from "@mfederczuk/custom-exception";

class CustomException extends Exception {
	constructor(readonly n: number, cause: (Exception | Error | null) = null) {
		super(`custom message ${n}`, cause);
	}
}

throw new CustomException(12);

Contributing

Read through the Custom JavaScript Exception Contribution Guidelines if you want to contribute to this project.

License

GNU GPLv3+