Last active
July 13, 2017 07:21
-
-
Save mrister/8ba7f65fbe39b6e14f7c57ddf731ecd8 to your computer and use it in GitHub Desktop.
A custom Node.js ES6 error.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://gist.github.com/mrister/8ba7f65fbe39b6e14f7c57ddf731ecd8#file-custom-es6-node-error-L16 is redundant with
super(message);