Custom Errors in ES6 (ES2015)
A very quick note. With the new class
and extend
keywords it’s now much easier to subclass Error
constructor:
class MyError extends Error {
constructor(message) {
super(message);
this.message = message;
this.name = 'MyError';
}
}
There is no need for this.stack = (new Error()).stack;
trick thanks to super()
call.