15-150: Principles of Functional Programming

Lecture 13: Exceptions

Exceptions play an important role in the system of static and dynamic checks that make SML a safe language.

Exceptions are the first type of effect that we encountered in this course; 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 n-Queens based on options and a third implementation based on continuations.

Key Concepts

Sample Code

Some Notes on Exceptions

Some Notes on the n-Queens Problem