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