-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathMethNestTry.java
More file actions
37 lines (30 loc) · 1.11 KB
/
MethNestTry.java
File metadata and controls
37 lines (30 loc) · 1.11 KB
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
package chapter10;
public class MethNestTry {
static void nesttry(int a) {
try { //nested try block
/*
* If one command line arg is used then a divide by zero exception
* will be generated by the following code*/
if (a == 1) a = a / (a - a); //division by zero
/*If two command line args are used then generate an out of bounds exception*/
if (a == 2) {
int c[] = {1};
c[42] = 99; //generate out of bounds exception
}
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Array Index out of bounds " + e);
}
}
public static void main(String[] args) {
try {
int a = 1; //args.length;
/*If no command line args are presented the following statement will generate
* a divide by zero exception */
int b = 42 / a;
System.out.println("a = " + a);
nesttry(a);
} catch (ArithmeticException e) {
System.out.println("Divide by zero " + e);
}
}
}