Last active
June 11, 2018 02:16
-
-
Save envynoiz/620486d670a4accd083bc7ea1d623fb5 to your computer and use it in GitHub Desktop.
Creating a custom exception using ECMAScript 6
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
class CustomException extends Error { | |
constructor(message) { | |
super(message); | |
this.name = this.constructor.name; | |
if ('function' === typeof Error.captureStackTrace) { | |
Error.captureStackTrace(this, this.constructor); | |
} else { | |
this.stack = (new Error(message)).stack; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment