Create try catch throw
This commit is contained in:
parent
4c1842233d
commit
2e01f4e724
15
Chapter 12/try catch throw
Normal file
15
Chapter 12/try catch throw
Normal file
@ -0,0 +1,15 @@
|
||||
function test(val) {
|
||||
try {
|
||||
if (isNaN(val)) {
|
||||
throw "Not a number";
|
||||
} else {
|
||||
console.log("Got number");
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
} finally {
|
||||
console.log("Done " + val);
|
||||
}
|
||||
}
|
||||
test("a");
|
||||
test(100);
|
||||
Loading…
x
Reference in New Issue
Block a user