- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNestedTryCatch.java
More file actions
Latest commit
29 lines (28 loc) · 1007 Bytes
/
Copy pathNestedTryCatch.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
importjava.util.Scanner;
publicclassNestedTryCatch {
publicstaticvoidmain(String[] args) {
int [] marks = newint[3];
marks[0] = 7;
marks[1] = 56;
marks[2] = 6;
Scannersc = newScanner(System.in);
booleanflag = true;
while(flag) {
System.out.println("Enter the value of index");
intind = sc.nextInt();
try {
System.out.println("Welcome to the nested try catch in java");
try {
System.out.println(marks[ind]);
flag = false;
} catch (ArrayIndexOutOfBoundsExceptione) {
System.out.println("Sorry this index does not exist");
System.out.println("Exception in level 2");
}
} catch (Exceptione) {
System.out.println("Exception in level 1");
}
}
System.out.println("Thanks for using this program");
}
}