KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > Finally


1 /* Finally.java */
2
3 import org.quilt.cl.RunTest;
4
5 /** A class with a finally clause in it. */
6
7 public class Finally implements RunTest {
8     private int value = -2;
9     
10     public Finally() { }
11
12     public void setValue( int i ) {
13         value = i;
14     }
15
16     /**
17      * @return -1, because the finally clause is always executed
18      */

19     public int runTest(int x) {
20         try {
21             if (x == 1) {
22                 throw new Exception JavaDoc("Finally Exception");
23             }
24         } catch ( Exception JavaDoc e) {
25             ;
26         } finally {
27             setValue( -1 );
28         }
29         return value;
30     }
31 }
32
Popular Tags