Created
August 5, 2016 11:10
-
-
Save mrister/b04e91a643001894b87e20b7fe179534 to your computer and use it in GitHub Desktop.
A simple custom Node.js ES6 Error
This file contains 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; | |
this.message = message; | |
} | |
} | |
// 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