KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Finally2Catches


1 /**
2  * A class with two catches and a finally clause.
3  *
4  * @author < a HREF="jddixon@users.sourceforge.net">Jim Dixon</a>
5  */

6
7 public class Finally2Catches implements org.quilt.cl.RunTest {
8     private int a,
9                 b,
10                 c;
11     private int array[] = {0, 1, 2, 3, 4, 5};
12
13     public Finally2Catches() {
14     }
15
16     public int runTest(int x) {
17         a = 2; // A: catch tracker
18
b = 3; // finally tracker
19
c = 5; // got-to-F
20
int d; // causes exceptions
21
try {
22             a *= a; // B: in try block
23
d = 1/x; // ArithEx if x is 0
24
d = array[x]; // out of bounds if x < 0 or x > 5
25
if (x==2) {
26                 throw new IllegalArgumentException JavaDoc();
27             }
28         } catch (ArithmeticException JavaDoc e) {
29             a *= a; // C:
30
throw e;
31         } catch (ArrayIndexOutOfBoundsException JavaDoc e) {
32             a *= a; // D:
33
} finally {
34             b *= b; // E:
35
}
36         c *= 5; // F:
37
return a*b*c; // encodes path in powers of prime numbers
38
}
39 }
40
Popular Tags