Skip to content

Instantly share code, notes, and snippets.

@mrister
Last active July 13, 2017 07:21
Show Gist options
  • Save mrister/8ba7f65fbe39b6e14f7c57ddf731ecd8 to your computer and use it in GitHub Desktop.
Save mrister/8ba7f65fbe39b6e14f7c57ddf731ecd8 to your computer and use it in GitHub Desktop.
A custom Node.js ES6 error.
/**
* A custom MyError class
* @class
*/
class MyError extends Error {
/**
* Constructs the MyError class
* @param {String} message an error message
* @constructor
*/
constructor(message) {
super(message);
// properly capture stack trace in Node.js
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
}
}
// test it
throw new MyError('test');
//MyError: test
@mathieug
Copy link

@mrister
Copy link
Author

mrister commented Jul 13, 2017

Indeed, thanks @mathieug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment