X-Git-Url: https://feistymeow.org/gitweb/?a=blobdiff_plain;f=kona%2Fsrc%2Ftest%2Fjava%2Fsemantics%2Fbehavior_of_finally_when_exception_in_catch.java;fp=kona%2Fsrc%2Ftest%2Fjava%2Fsemantics%2Fbehavior_of_finally_when_exception_in_catch.java;h=e722b130e06fbc58a7ca69b296ce40d205625923;hb=42bf14e9cfbee5ee218bb6a775e3d7b90e9e491c;hp=0000000000000000000000000000000000000000;hpb=5ecfd83bfba80a156a76866185ccef54a9e03315;p=feisty_meow.git diff --git a/kona/src/test/java/semantics/behavior_of_finally_when_exception_in_catch.java b/kona/src/test/java/semantics/behavior_of_finally_when_exception_in_catch.java new file mode 100644 index 00000000..e722b130 --- /dev/null +++ b/kona/src/test/java/semantics/behavior_of_finally_when_exception_in_catch.java @@ -0,0 +1,52 @@ +package test.java.semantics; + +import java.io.FileNotFoundException; + +class finally_behavior_test +{ + int calibrador = 17; + + public finally_behavior_test() + { + } + + public int funkyTown() throws FileNotFoundException + { + if (calibrador < 3) { + // we should never get here. it should always raise an exception. + System.out.println("where did you put it?"); + } else { + throw new FileNotFoundException("is it larger than a breadbox?"); + } + return 25; + } + + public void runTest() throws Throwable + { + try { + int zooty = funkyTown(); + System.out.println("zooty is " + zooty + " but how did we get here???"); + } catch (Throwable cause) { + System.out.println("caught exception, now will rethrow."); + throw cause; + } finally { + System.out.println("still got to finally, our assumptions are safe."); + } + } + + public static void main(String s[]) throws Exception + { + // we are asserting that the finally clause of an exception handler will still + // fire when an exception is raised in the catch clause. otherwise, all our + // assumptions about being able to use finally properly are thrown out the window. + finally_behavior_test tony = new finally_behavior_test(); + try { + tony.runTest(); + } catch (Throwable cause) { + //yawn. + } + System.out.println("Hey, did the finally clause say it ran above?"); + System.out.println("If so, great. If not, we've got problems."); + } + +}