Utility for creating custom JavaScript errors
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
.lint
.travis.yml
CHANGES
LICENSE
README.md
abstract.js
index.js
package.json

README.md

error-create

Utility for creating custom JavaScript errors

Usage

var MyCustomError = require('error-create')('MyCustomError');

try {
  throw new MyCustomError("My message", 'MY_CODE', { foo: 'bar' });
} catch (e) {
  console.log(e instanceof Error);         // true
  console.log(e instanceof MyCustomError); // true
  console.log(String(e));                  // 'MyCustomError: My message'
  console.log(e.code);                     // 'MY_CODE'
  console.log(e.foo);                      // 'bar'
}

Installation

$ npm install error-create

To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: Browserify, Webmake or Webpack

Tests Build Status

$ npm test