-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathExceptionMulti.java
More file actions
34 lines (32 loc) · 887 Bytes
/
ExceptionMulti.java
File metadata and controls
34 lines (32 loc) · 887 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
30
31
32
33
34
// Demonstrating multiple catching of Exceptions
import java.util.*;
class ExceptionMulti
{
public static void main(String args[])
{
int a[] = {5,10};
int b = 5;
try
{
int x = a[2] / b - a[1]; // a[2] is non-existant
System.out.println("x = " + x);
}
catch(ArithmeticException e)
{
System.out.println("Division by Zero"); // never happen in this code
}
catch(ArrayIndexOutOfBoundsException e)
{
System.out.println("Array Index Error"); // We will get this
}
catch(ArrayStoreException e)
{
System.out.println("Wrong Datatype"); // Will be ignored
}
finally
{
int y = a[1] / a[0];
System.out.println("y = " +y); // a = 2
}
}
}