-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionDemoNested.java
More file actions
23 lines (23 loc) · 897 Bytes
/
Copy pathExceptionDemoNested.java
File metadata and controls
23 lines (23 loc) · 897 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class ExceptionDemoNested {
public static void main(String[] args) {
// Here, numer is longer than denom.
int[] numer = { 4, 8, 16, 32, 64, 128, 256, 512 };
int[] denom = { 2, 0, 4, 4, 0, 8 };
try { // outer try
for (int i = 0; i<numer.length; i++) {
try { // nested try
System.out.println(numer[i] + " / " + denom[i] + " is " + numer[i]/denom[i]);
}
catch (ArithmeticException exc) {
// Catch the exception.
System.out.println("Can't divide by Zero!");
}
}
}
catch (ArrayIndexOutOfBoundsException exc) {
// Catch the exception.
System.out.println("No matching element found.");
System.out.println("Fatal error - program terminated.");
}
}
}