Last active
December 25, 2018 09:35
-
-
Save mrister/0114f50bcb1e5bd6ed60ff9c377ef2d7 to your computer and use it in GitHub Desktop.
A simple custom Node.js 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 | |
* @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