Last active
February 18, 2017 17:31
-
-
Save kaplanmaxe/0263fc81bde31e9183403fd5ddba7871 to your computer and use it in GitHub Desktop.
Throwing Errors in JS
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
/** | |
* 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