-
-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathNested Try-Catch in Java
31 lines (29 loc) · 1022 Bytes
/
Nested Try-Catch in Java
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
package com.company;
import java.util.Scanner;
public class cwh_82_nested_try_catch {
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 video no 82");
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");
}
}