Muqriz 48f16bfc3e initail first | 4 个月前 | |
---|---|---|
.. | ||
es6 | 4 个月前 | |
lib | 4 个月前 | |
typings | 4 个月前 | |
CHANGELOG.md | 4 个月前 | |
LICENSE.md | 4 个月前 | |
README.md | 4 个月前 | |
package.json | 4 个月前 |
An easily-extendable error class for use with ES6 classes (or ES5, if you so choose).
Tested in Node 4.0, Chrome, and Firefox.
I made this because I wanted to be able to extend Error for inheritance and type
checking, but can never remember to add
Error.captureStackTrace(this, this.constructor.name)
to the constructor or how
to get the proper name to print from console.log
.
import ExtendableError from 'es6-error';
class MyError extends ExtendableError {
// constructor is optional; you should omit it if you just want a custom error
// type for inheritance and type checking
constructor(message = 'Default message') {
super(message);
}
}
export default MyError;
var util = require('util');
var ExtendableError = require('es6-error');
function MyError(message) {
message = message || 'Default message';
ExtendableError.call(this, message);
}
util.inherits(MyError, ExtendableError);
module.exports = MyError;