12 Handling Exceptions

Handling exceptions that have been raised can be done with pattern matching

A try exception is essentially pattern matching, but only on exceptions

Syntax

try e with 
    | p1 -> e1
    | ...
    | pn -> en

You can have $[1, \infty)$ branches.

Evaluation

if e ==> v then (try e...) ==> v

if e raises an exception x, then match x against the patterns. If none match, then re-raise x.

Type checking

(try e ...) : t if e : t and e : t and ei : t and pi : exn.