Created
March 5, 2015 11:52
-
-
Save shigemk2/635ed44593c37dac49ab to your computer and use it in GitHub Desktop.
This file contains 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
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