newerror
Create Error subclasses without sweating it!
How?
var newError = ; var StuffError = ; // [...]try throw ; catch e console; // true
Why?
Creating a new Error subclass is quite easy, but there are some things you shouldn't forget:
- The stack has to be re-created or the stack trace is lost.
- The prototype has to be correctly set.
- The
name
property has to be correctly set.
So this module is just to ease the creation of Error subclasses, and never get it wrong.
API
The newError
function takes 2 arguments:
type
: the name of the new Error subclass.message
: the default message when an error is thrown.
To use this function:
var newError = ; var StuffError = ;throw ; // "StuffError: test"throw 'another test'; // "StuffError: another test"
Contributors
License
MIT License.