Exceptions play an important role in the system of static and dynamic checks that make SML a safe language.
Exceptions may cause an evaluation to be interrupted or aborted. (Think of division by 0.)
One simple use of exceptions is to signal that invariants are violated or exceptional boundary cases are encountered.
Exceptions can sometimes also be used in backtracking search procedures or other patterns of control flow where a computation needs to be partially undone. We demonstrated this with an n-Queens implementation. We also showed an implementation of n-Queens based on continuations. In addition, the code below contains an implementation based on options (which we discussed very briefly at the end of lecture).
The code from the 3pm lecture contains a bonus section at the end,
in which the success continuation has two (curried) arguments: the
list of queen placements
That setup is enormously expressive. We can now compute one solution,
all solutions, count solutions, etc., simply by changing the success
continuation slightly, without changing the internals of the
addqueen function.