Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.