Skip to content

Instantly share code, notes, and snippets.

@mrister
Last active December 25, 2018 09:35
Show Gist options
  • Save mrister/0114f50bcb1e5bd6ed60ff9c377ef2d7 to your computer and use it in GitHub Desktop.
Save mrister/0114f50bcb1e5bd6ed60ff9c377ef2d7 to your computer and use it in GitHub Desktop.
A simple custom Node.js error
/**
* A custom MyError
* @param {String} message a message to store in error
* @constructor
*/
function MyError(message) {
this.constructor.prototype.__proto__ = Error.prototype;
// properly capture stack trace in Node.js
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = message;
}
// to test use:
throw new MyError('test');
//MyError: test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment