1 package test.java.semantics;
3 import java.io.FileNotFoundException;
5 //hmmm: convert this to simple unit test.
6 public class behavior_of_finally_when_exception_in_catch
8 private int calibrador = 17;
10 private boolean ranRight = false;
12 public behavior_of_finally_when_exception_in_catch()
16 public int funkyTown() throws FileNotFoundException
19 // we should never get here. it should always raise an exception.
20 System.out.println("where did you put it?");
22 throw new FileNotFoundException("is it larger than a breadbox?");
27 public void runTest() throws Throwable
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.");
36 System.out.println("ran finally clause; our assumptions are safe. we MUST see this line!!");
41 public static void main(String s[]) throws Exception
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();
49 } catch (Throwable cause) {
52 System.out.println("the finally clause needs to have run above; otherwise, we've got bad problems.");
54 System.out.println("FAILURE in assumptions about the finally clause!!!");
56 System.out.println("okay, cool. test succeeded.");