Created
January 10, 2017 16:02
-
-
Save acanimal/373f7a4104dbd04de603e30166069805 to your computer and use it in GitHub Desktop.
Custom error in ES6
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
class ExtendableError extends Error { | |
constructor(message) { | |
super(message); | |
this.name = this.constructor.name; | |
this.message = message; | |
if (typeof Error.captureStackTrace === 'function') { | |
Error.captureStackTrace(this, this.constructor); | |
} else { | |
this.stack = (new Error(message)).stack; | |
} | |
} | |
} | |
// See: http://stackoverflow.com/questions/31089801/extending-error-in-javascript-with-es6-syntax |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment