The reader is encouraged to imagine how one might structure this program without the use of exceptions. Another typical use of exceptions is to implement backtracking , a programming technique based on exhaustive search of a state space. A very simple, albeit somewhat artificial, example is provided by the following function to compute change from an arbitrary list of coin values. Given only a 5 cent and a 2 cent coin, we cannot make 16 cents in change by first taking three 5's and then proceeding to dole out 2's. In fact we must use two 5's and three 2's to make 16 cents.
Exceptions can also carry values.
For example, we might associate with a SyntaxError exception a string indicating the precise nature of the error. Such an exception is introduced by the declaration exception SyntaxError of string which introduces the exception SyntaxError as an exception carrying a string as value. This declaration introduces the exception constructor SyntaxError . Exception constructors are in many ways similar to value constructors. Exception constructors raise the question of the status of exceptions in the language.