Skip to content

Instantly share code, notes, and snippets.

@shigemk2
Created March 5, 2015 11:52
Show Gist options
  • Save shigemk2/635ed44593c37dac49ab to your computer and use it in GitHub Desktop.
Save shigemk2/635ed44593c37dac49ab to your computer and use it in GitHub Desktop.
function trycatch(x) {
try {
if(x > 10) {
throw "Err1";
}
else if(x < 0) {
throw "Err2";
}
else if(isNaN(x)) {
throw "Err3";
} else {
console.log(x);
}
} catch(er) {
if(er=="Err1") {
console.log("Error! The value is too high");
} if(er=="Err2") {
console.log("Error! The value is too low");
} if(er=="Err3") {
console.log("Error! The value is not a number");
}
}
}
trycatch(1);
trycatch(10);
trycatch(99);
trycatch("hogehoge");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment