my-error

0.1.0 • Public • Published

my-error

build npm npm npm

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 ms@development.co.il, MIT License

Package Sidebar

Install

npm i my-error

Weekly Downloads

1

Version

0.1.0

License

MIT

Last publish

Collaborators

  • moshe