-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMultiTryCatch.java
More file actions
44 lines (32 loc) · 943 Bytes
/
MultiTryCatch.java
File metadata and controls
44 lines (32 loc) · 943 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package exhand;
public class MultiTryCatch {
public static void main(String[] args) {
try {
MultiTryCatch obj = new MultiTryCatch();
int divideResult = 0;
try {
divideResult = obj.divide(10, 0); // Error:divide by 0
} catch (ArithmeticException e) {
System.out.println("ERROR: 10/0");
e.printStackTrace();
}
try {
int[] arr = new int[5];
arr[10] = 50; // Error: index is 10, array size is only 5
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("ERROR: Array Size: 5, item insert index:10");
e.printStackTrace();
}
System.out.println(divideResult);
String str = null;
System.out.println(str.length()); // Error: method call in null
// value
} catch (Exception e) {
System.out.println("Exception Root.");
e.printStackTrace();
}
}
public int divide(int a, int b) {
return a / b;
}
}