Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including c-e with all npm packages installed. Try it out:

var cE = require("c-e")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

c-e v1.0.4

Making custom error classes

c-e

Making custom error classes

Build Status NPM version

Install

npm i c-e

Usage

const ce = require('c-e');

const CustomError = ce();
const NestedError = ce('NestedError', CustomError);

CustomError.name === 'CustomError';         // true
NestedError.name === 'NestedError';         // true
new CustomError().name === 'CustomError';   // true
new NestedError().name === 'NestedError';   // true
new NestedError('test').message === 'test'; // true
new NestedError() instanceof Error;         // true
new NestedError() instanceof CustomError;   // true
new NestedError() instanceof NestedError;   // true

const MyError = ce('MyError', Error, function(a, b){
    this.message = `${a + b}`;
    this.a = a;
    this.b = b;
});
new MyError(1, 2).message === '3'; // true
new MyError(1, 2).a === 1;         // true
new MyError(1, 2).b === 2;         // true

License

MIT

Metadata

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free