make-error
Make your own error types!
Features
- Compatible Node & browsers
instanceof
supporterror.name
&error.stack
support- compatible with CSP (i.e. no
eval()
)
Installation
Browserify/Webpack
Node &Installation of the npm package:
> npm install --save make-error
Then require the package:
var makeError = ;
Browser
You can directly use the build provided at unpkg.com:
Usage
Basic named error
var CustomError = ; // Parameters are forwarded to the super class (here Error).throw "a message";
Advanced error class
{ CustomErrorsuper; thiscustomValue = customValue;}; // Feel free to extend the prototype.CustomErrorprototype { console;}; //----- try throw 42; catch error error;
Specialized error
var SpecializedError = ; throw 42;
Inheritance
Best for ES2015+.
; { super"custom error message"; }
Related
- make-error-cause: Make your own error types, with a cause!
Contributions
Contributions are very welcomed, either on the documentation or on the code.
You may:
- report any issue you've encountered;
- fork and create a pull request.
License
ISC © Julien Fontanet