Skip to content

Instantly share code, notes, and snippets.

@kaplanmaxe
Last active February 18, 2017 17:31
Show Gist options
  • Save kaplanmaxe/0263fc81bde31e9183403fd5ddba7871 to your computer and use it in GitHub Desktop.
Save kaplanmaxe/0263fc81bde31e9183403fd5ddba7871 to your computer and use it in GitHub Desktop.
Throwing Errors in JS
/**
* The proper way of throwing an error in JavaScript. Even prints a stack trace for you!
*/
throw new Error('I am learning way too much JS in one day');
/**
* Now we can even make our own errors.
*/
function LearningError(message) {
this.message = message;
console.trace();
}
throw new LearningError('Help, my brain is overloading with all this JS!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment