Skip to content

Instantly share code, notes, and snippets.

@envynoiz
Last active June 11, 2018 02:16
Show Gist options
  • Save envynoiz/620486d670a4accd083bc7ea1d623fb5 to your computer and use it in GitHub Desktop.
Save envynoiz/620486d670a4accd083bc7ea1d623fb5 to your computer and use it in GitHub Desktop.
Creating a custom exception using ECMAScript 6
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