Skip to content

Instantly share code, notes, and snippets.

@andijakl
Created September 12, 2018 12:37
Show Gist options
  • Save andijakl/143392d4200a6582ae3b512326ea7921 to your computer and use it in GitHub Desktop.
Save andijakl/143392d4200a6582ae3b512326ea7921 to your computer and use it in GitHub Desktop.
Try / Catch in JavaScript
var weight = -12.2;
try {
if (weight < 0) {
throw "Weight can not be less than 0";
}
console.log("Saving today's weight to database...");
} catch(error) {
console.log(error);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment