-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHandling_Exception.java
More file actions
32 lines (30 loc) · 1.1 KB
/
Handling_Exception.java
File metadata and controls
32 lines (30 loc) · 1.1 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
import java.util.Scanner;
public class Handling_Exception {
public static void main(String[] args) {
int [] marks = new int[3];
marks[0] = 7;
marks[1] = 45;
marks[2] = 99;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the array index");
int ind = sc.nextInt();
System.out.println("Enter the number you want to divide the value with");
int number = sc.nextInt();
try {
System.out.println("The value at array index entered is: " + marks[ind]);
System.out.println("The value of array-value/number is: " + marks[ind]/number);
}
catch (ArithmeticException e){
System.out.println("ArithmeticException occured!");
System.out.println(e);
}
catch (ArrayIndexOutOfBoundsException e){
System.out.println("ArrayIndexOutOfBoundsException occured!");
System.out.println(e);
}
catch (Exception e){
System.out.println("Some other exception occured!");
System.out.println(e);
}
}
}