A custom JavaScript exception class.
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);
Using npm:
npm i @mfederczuk/custom-js-exception
Using Yarn:
yarn add @mfederczuk/custom-js-exception
Read through the Contribution Guidelines if you want to contribute to this project.
Custom JavaScript Exception is licensed under both the Mozilla Public License 2.0 AND
the Apache License 2.0.
For more information about copying and licensing, see the COPYING.txt
file.