Skip to content

Commit c225c98

Browse files
committed
Try Catch Throw
1 parent 2ab9337 commit c225c98

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

try-catch-throw.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
! The try statement lets you test a block of code for errors.
3+
4+
! The catch statement lets you handle the error.
5+
6+
! The throw statement lets you create custom errors.
7+
*/
8+
let values = [1, 2, 3, 4, 5, 6, 7, 8, 9];
9+
10+
try {
11+
values.forEach((item, index) => {
12+
if (item > 5) {
13+
throw new Exception("Limit exceeded");
14+
}
15+
16+
console.log(`At ${index + 1} is number ${item}`);
17+
});
18+
} catch (err) {
19+
console.log("Loop is done");
20+
}

0 commit comments

Comments
 (0)