Syntactic sugar for referencing and throwing common named and custom errors/exceptions

Usage no npm install needed!

<script type="module">
  import exceptions from 'https://cdn.skypack.dev/exceptions';



Trivial API and associated static instances of Exception that make it slightly simpler to throw common and custom exceptions that are not already available in Javascript. Using static instances for Exceptions also helps to maintain consistency between exception names both when throwing and catching (and reduces the likelihood of typos in name literal strings causing bugs).

The idea is that this works with the current Javascript Error mechanism as a complement to it. Exceptions and Errors are meant to co-exist - in fact all Exceptions really do is throw Errors and provide a well defined means to compare Errors within a catch block (for example).

Hopefully the list of static common Exception instances will grow over time.


$npm install exceptions

Alternatively include as a dependency within your package.json and:

$npm link


var exceptions = require("exceptions");

Then invoke the provided APIs on instances of Error or Error.stack as required.


See test/testExceptions.js for some examples.


Tests utilise nodeunit. In addition jshint is run against both lib and test javascript files.

First install the dependencies:

$ npm link

Then to run the tests:

$ npm test