-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNestedTryCatch.java
More file actions
29 lines (28 loc) · 1007 Bytes
/
NestedTryCatch.java
File metadata and controls
29 lines (28 loc) · 1007 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
import java.util.Scanner;
public class NestedTryCatch {
public static void main(String[] args) {
int [] marks = new int[3];
marks[0] = 7;
marks[1] = 56;
marks[2] = 6;
Scanner sc = new Scanner(System.in);
boolean flag = true;
while(flag) {
System.out.println("Enter the value of index");
int ind = sc.nextInt();
try {
System.out.println("Welcome to the nested try catch in java");
try {
System.out.println(marks[ind]);
flag = false;
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Sorry this index does not exist");
System.out.println("Exception in level 2");
}
} catch (Exception e) {
System.out.println("Exception in level 1");
}
}
System.out.println("Thanks for using this program");
}
}