my-error
v0.1.0
Published
Custom Error class for `util.inherits`
Downloads
16
Maintainers
Readme
my-error
Custom Error class for util.inherits
.
Installation
npm install my-error --save
Usage
var MyError = require('my-error');
// create your custom error
function CodeError(code, message) {
CodeError.super_.call(this, message);
this.code = code;
}
util.inherits(CodeError, MyError);
// later on..
try {
throw new CodeError(404, 'Not Found!');
} catch (err) {
// do some thing...
// err.name === 'CodeError';
// err.code === 404;
// err.message === 'Not Found!';
// err instanceof CodeError;
// err instanceof Error;
}
License
Copyright © 2015 Moshe Simantov [email protected], MIT License