import java.io.FileNotFoundException;
-class finally_behavior_test
+//hmmm: convert this to simple unit test.
+public class behavior_of_finally_when_exception_in_catch
{
- int calibrador = 17;
+ private int calibrador = 17;
- public finally_behavior_test()
- {
- }
+ private boolean ranRight = false;
- 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 behavior_of_finally_when_exception_in_catch()
+ {
+ }
- 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 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 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.");
- }
+ 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. so far this is fine.");
+ throw cause;
+ } finally {
+ System.out.println("ran finally clause; our assumptions are safe. we MUST see this line!!");
+ ranRight = true;
+ }
+ }
+ 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.
+ behavior_of_finally_when_exception_in_catch tony = new behavior_of_finally_when_exception_in_catch();
+ try {
+ tony.runTest();
+ } catch (Throwable cause) {
+ // yawn.
+ }
+ System.out.println("the finally clause needs to have run above; otherwise, we've got bad problems.");
+ if (!tony.ranRight) {
+ System.out.println("FAILURE in assumptions about the finally clause!!!");
+ } else {
+ System.out.println("okay, cool. test succeeded.");
+ }
+ }
}
import java.util.List;
+//hmmm: convert this to simple unit test.
class instance_of
{
- public instance_of() {}
-
- public Object cogitate() {
- return null;
- }
+ public instance_of()
+ {
+ }
- public static void main(String s[]) throws Exception
- {
- // we are just asserting that it is safe to do instanceof on an object that is null.
- // let's test that theory.
- instance_of tony = new instance_of();
- Object fred = tony.cogitate(); // will produce null.
- if (fred instanceof List<?>) {
- throw new Exception("that should not have happened!");
- } else {
- System.out.println("told us null is not an instance of List, which is correct.");
- }
-
- }
+ public Object cogitate()
+ {
+ return null;
+ }
+
+ public static void main(String s[]) throws Exception
+ {
+ // we are just asserting that it is safe to do instanceof on an object that is null.
+ // let's test that theory.
+ instance_of tony = new instance_of();
+ Object fred = tony.cogitate(); // will produce null.
+ if (fred instanceof List<?>) {
+ throw new Exception("FAILURE! fred should not be instance of List<?> ! null is an instance of something!");
+ } else {
+ System.out.println("told us null is not an instance of List, which is correct.");
+ }
+ }
}
\ No newline at end of file