Skip to content

Commit 1e71e9a

Browse files
committed
Add Ex21
1 parent eeb027d commit 1e71e9a

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package Exercise21;
2+
3+
public class Test {
4+
public static void main(String[] args) {
5+
6+
int[] array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
7+
try{
8+
anonymousMethod(array);
9+
}
10+
catch (Exception e) {
11+
System.out.printf("Catches %s from the outer catch block\n", e.getClass().getSimpleName());
12+
}
13+
}
14+
15+
16+
static void anonymousMethod(int[] array) {
17+
try{
18+
array[array.length + 5] = 3 / 0;
19+
} catch (ArrayIndexOutOfBoundsException e) {
20+
System.out.printf("Catches %s inside the anonymousMethod\n", e.getClass().getSimpleName());
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)