June 2005
Beginner to intermediate
312 pages
6h 24m
English
The puzzles in this chapter concern exceptions and the closely related try-finally statement. A word of caution: Puzzle 44 is exceptionally difficult.
This poor little program can’t quite make up its mind. The decision method returns true. But it also returns false. What does it print? Is it even legal?
public class Indecisive { public static void main(String[ ] args) { System.out.println(decision( ) ); } static boolean decision( ) { try { return true; } finally { return false; } }}
You might think that this program is illegal. After all, the decision method can’t return both true and false. If you tried ...