20-CS-694 Advanced Programming Techniques Spring 2012
Hints for Homework Assignment 2

Interfaces, Exceptions, Graphics, Animation, Threads, Reflection, Networking, RMI, JDBC, JNI

Exceptions for Control - Declarative Style

Due: April 17, 2012 (submit instructions: here)

Up and Out:
  public class Up extends Exception {}
  public class Out extends Exception {}  
The Up exception can be used to quit to a higher level, the Out exception can be used to leave the computation.
    Each Choose object executes the for loop for a particular variable. All variable values are given to the variable until either all constraints are satisfied or until all are exhausted. In the latter case an Up exception is thrown. All the for loops are linked, in order of nesting, through the Choose constructor.
    The Puzzle class contains checkit and solve. The checkit function tries variable values until all constraints are satisfied. The solve function holds all the Choose statements which are all linked, in succession, the last link being this (Puzzle) object.
    This is an interface requiring the method checkit which can throw exceptions Up and Out and method Val which returns a String. The checkit() method catches an Up exception from its Choose object: this is what keeps the loop going until it ends and, when that happens, checkit() throws an Up to the next higher level. Both the Puzzle and Choose classes implement this interface.

More Help