15-150: Principles of Functional Programming

Lecture 13: Regular Expressions and Exceptions

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 options.

Key Concepts

Sample Code This file contains an implementation of n-Queens using a failure continuation in addition to the examples we covered in the lecture.

Some Notes on Exceptions

Some Notes on the n-Queens Problem

Slides from Lecture