[previous] [up] [next]     [contents] [index]
Next: Threads and Namespaces Up: Exceptions and Control Flow Previous: User Breaks

Error Escape Handler

Special control flow for errors is performed an error escape handler that is called by the default exception handler.[footnote] An error escape handler takes no arguments and must escape from the expression that raised the error.

Generally, the error escape handler is only called directly by an exception handler. To escape from a run-time error, use raise (see section 8.1) or error (see section 8.2) instead.

If an exception is raised while the error escape handler is executing, an error message is printed using a primitive error printer and the primitive error escape handler is invoked.

In the following example, the error escape handler is set so that errors do not escape from a custom read-eval-print loop:

  (let ([orig (error-escape-handler)])
    (let/ec exit
      (let retry-loop ()
        (let/ec escape
          (error-escape-handler
           (lambda () (escape #f)))
          (let loop ()
            (let ([e (my-read)])
              (if (eof-object? e)
                  (exit 'done)
                  (let ([v (my-eval e)])
                    (my-print v)
                    (loop))))))
        (retry-loop)))
    (error-escape-handler orig))

See also read-eval-print-loop in section 14.1 for a simpler implementation of this example.



PLT