cbccf0a7fe16baad9856f03472cf0e2533b843d1
[feisty_meow.git] / kona / z-testing / src / test / java / semantics / behavior_of_finally_when_exception_in_catch.java
1 package test.java.semantics;
2
3 import java.io.FileNotFoundException;
4
5 //import java.util.List;
6
7 class finally_behavior_test
8 {
9     int calibrador = 17;
10
11     public finally_behavior_test()
12     {
13     }
14
15     public int funkyTown() throws FileNotFoundException
16     {
17         if (calibrador < 3) {
18             // we should never get here.  it should always raise an exception.
19             System.out.println("where did you put it?");
20         } else {
21             throw new FileNotFoundException("is it larger than a breadbox?");
22         }
23         return 25;
24     }
25
26     public void runTest() throws Throwable
27     {
28         try {
29             int zooty = funkyTown();
30             System.out.println("zooty is " + zooty + " but how did we get here???");
31         } catch (Throwable cause) {
32             System.out.println("caught exception, now will rethrow.");
33             throw cause;
34         } finally {
35             System.out.println("still got to finally, our assumptions are safe.");
36         }
37     }
38
39     public static void main(String s[]) throws Exception
40     {
41         // we are asserting that the finally clause of an exception handler will still
42         // fire when an exception is raised in the catch clause. otherwise, all our
43         // assumptions about being able to use finally properly are thrown out the window.
44         finally_behavior_test tony = new finally_behavior_test();
45         try {
46             tony.runTest();
47         } catch (Throwable cause) {
48             //yawn.
49         }
50         System.out.println("Hey, did the finally clause say it ran above?");
51         System.out.println("If so, great.  If not, we've got problems.");
52     }
53
54 }