MzScheme supports the exception system proposed by Friedman, Haynes, and Dybvig. MzScheme's implementation extends that proposal by defining the specific exception values that are raised by each primitive error.
The default exception handler prints an error message using the current error display handler (see section 3.12) and then escapes by calling the current error escape handler (see section 3.13). If an exception is raised while the exeception handler is executing, an error message is printed using a primitive error printer and the primitive error escape handler is invoked.
When an exception is raised during the evaluation of exprs, each predicate procedure pred is applied to the exception value; if a predicate returns a true value, the corresponding handler procedure is invoked with the exception as an argument. The predicates are tried in the order that they are specified. The pred and handler expressions are evaluated in the order that they are specified, before the first expr and before the exception handler is changed.
Before any predicate or handler procedure is invoked, the continuation of the entire with-handlers expression is restored. The ``original'' exception handler (the one present before the with-handlers expression was evaluated) is therefore re-installed before any predicate or handler procedure is invoked.
This example defines a divide procedure that returns +inf.0 when dividing by zero instead of signalling an exception (other exceptions raised by / are signalled):
(define div-w-inf
(lambda (n d)
(with-handlers ([exn:application:math:zero?
(lambda (exn) +inf.0)])
(/ n d))))