File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Demonstrating multiple catching of Exceptions
2
+
3
+ import java .util .*;
4
+ class ExceptionMulti
5
+ {
6
+ public static void main (String args [])
7
+ {
8
+ int a [] = {5 ,10 };
9
+ int b = 5 ;
10
+
11
+ try
12
+ {
13
+ int x = a [2 ] / b - a [1 ]; // a[2] is non-existant
14
+ System .out .println ("x = " + x );
15
+ }
16
+ catch (ArithmeticException e )
17
+ {
18
+ System .out .println ("Division by Zero" ); // never happen in this code
19
+ }
20
+ catch (ArrayIndexOutOfBoundsException e )
21
+ {
22
+ System .out .println ("Array Index Error" ); // We will get this
23
+ }
24
+ catch (ArrayStoreException e )
25
+ {
26
+ System .out .println ("Wrong Datatype" ); // Will be ignored
27
+ }
28
+ finally
29
+ {
30
+ int y = a [1 ] / a [0 ];
31
+ System .out .println ("y = " +y ); // a = 2
32
+ }
33
+ }
34
+ }
You can’t perform that action at this time.
0 commit comments