cleaned up these tests.
[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 //hmmm: convert this to simple unit test.
6 public class behavior_of_finally_when_exception_in_catch
7 {
8         private int calibrador = 17;
9
10         private boolean ranRight = false;
11
12         public behavior_of_finally_when_exception_in_catch()
13         {
14         }
15
16         public int funkyTown() throws FileNotFoundException
17         {
18                 if (calibrador < 3) {
19                         // we should never get here. it should always raise an exception.
20                         System.out.println("where did you put it?");
21                 } else {
22                         throw new FileNotFoundException("is it larger than a breadbox?");
23                 }
24                 return 25;
25         }
26
27         public void runTest() throws Throwable
28         {
29                 try {
30                         int zooty = funkyTown();
31                         System.out.println("zooty is " + zooty + " but how did we get here???");
32                 } catch (Throwable cause) {
33                         System.out.println("caught exception, now will rethrow.  so far this is fine.");
34                         throw cause;
35                 } finally {
36                         System.out.println("ran finally clause; our assumptions are safe.  we MUST see this line!!");
37                         ranRight = true;
38                 }
39         }
40
41         public static void main(String s[]) throws Exception
42         {
43                 // we are asserting that the finally clause of an exception handler will still
44                 // fire when an exception is raised in the catch clause. otherwise, all our
45                 // assumptions about being able to use finally properly are thrown out the window.
46                 behavior_of_finally_when_exception_in_catch tony = new behavior_of_finally_when_exception_in_catch();
47                 try {
48                         tony.runTest();
49                 } catch (Throwable cause) {
50                         // yawn.
51                 }
52                 System.out.println("the finally clause needs to have run above; otherwise, we've got bad problems.");
53                 if (!tony.ranRight) {
54                         System.out.println("FAILURE in assumptions about the finally clause!!!");
55                 } else {
56                         System.out.println("okay, cool.  test succeeded.");
57                 }
58         }
59 }