-
Notifications
You must be signed in to change notification settings - Fork 0
/
qb90.java
35 lines (29 loc) · 927 Bytes
/
qb90.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
32
33
34
35
// // By using try..catch..finally
//class ex17 {
// public static void main(String[] args) {
// int s[] = { 1, 2, 3 };
// try {
// System.out.println(s[5]);
// } catch (ArrayIndexOutOfBoundsException e) {
// System.out.println("Not Found");
// } finally {
// System.out.println("This is finally block..");
// }
// }
// }
//By using throw
class ex17 {
public static void main(String[] args) {
int[] numbers = { 1, 2, 3 };
int index = 5;
try {
if (index >= numbers.length) {
throw new ArrayIndexOutOfBoundsException("Index " + index + " is out of bounds for the array");
}
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println(e.getMessage());
} finally {
System.out.println("This is finally block");
}
}
}