ErrorSubclass
A JavaScript class that makes Error subclassable. It inherits from Error (in all the right ways), so that you can safely and easily create your own Error subclasses.
The provided class handles all the craziness for preserving stack traces and other things so that you don't have to worry about it. Create a class that inherits from it and you're good to go.
- instanceof Error
- instanceof <your subclass>
- stack traces
- .name === <name of subclass>
- .toString()
Usage
; static displayName = 'MyError'; // optional. survives minification // Add extra properties/methods if desired: { return 'MYERROR'; } // later...throw 'error message';
License
MIT