Skip to content

Instantly share code, notes, and snippets.

@acanimal
Created January 10, 2017 16:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acanimal/373f7a4104dbd04de603e30166069805 to your computer and use it in GitHub Desktop.
Save acanimal/373f7a4104dbd04de603e30166069805 to your computer and use it in GitHub Desktop.
Custom error in ES6
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