19.14 Exception handling expression exp handle match
This expression catches an exception raised during evaluation of expression exp. match is of the form
pat => exp
|
| pat => exp
that indicates the sequence of pairs of a exception pattern and expression to be evaluated if the raised exception is matched with the pattern.
Each pattern pat must includes an exception constructor and therefore be of exception type exn. The type of every expression exp must be identical to that of exp. This expression is evaluated as follows.
-
•
exp is evaluated at first. If this evaluation is normally finished, its value is the value of this entire expression.
-
•
If an exception is raised during the evaluation, it tries to match the exception with each pattern from pat to pat. If it a match succeeds, it binds variables in pat to corresponding parameters of the exception object and evaluates exp. The value of exp is the value of this entire expression.
-
•
If the exception does not match with any pattern, the exception is propagated to the outer expression surrounding this expression.