A technique is used in embodiments of the invention such that backtracking programs can be written in a general purpose computer language (e.g., C++ or Java) without requiring the control structure of the program to reflect the structure of the decision tree. A data state and a control state are restored during backtracking. For restoring the data state, embodiments of the invention keep track of the changes made to variables and the point in execution at which the changes are made. When backtracking occurs, the data state can be restored by undoing the changes to the desired point in execution. For restoring the control state, the method of the invention provides a "failure" exception state that is invoked upon failure in the program (e.g., a failure to find a solution in a search program).. The failure exception is "caught" by catch points established in the execution stack. The failure exception is passed up the execution stack until a point is reached prior to the failure at which execution should be re-initiated. Since the control structure of the search program need not have the same form as the decision tree, part of the control state for the desired decision point may no longer exist on the execution stack, so the catch point may not be directly associated with the desired point but merely preceed it. The remaining part of the control state is restored by re-executing the program in a special re-execution mode until the desired state is achieved and another alternative may be chosen.
21 Claims, 12 Drawing Sheets