[previous] [up] [next]     [index]
Next: Primitive Exceptions Up: Exceptions and Control Flow Previous: Exceptions and Control Flow

Exceptions

MzScheme supports the exception system proposed by Friedman, Haynes, and Dybvig.[footnote] MzScheme's implementation extends that proposal by defining the specific exception values that are raised by each primitive error.

The following example defines a divide procedure that returns +inf.0 when dividing by zero instead of signaling an exception (other exceptions raised by / are signaled):

  (define div-w-inf
    (lambda (n d)
      (with-handlers ([exn:application:math:zero? 
                       (lambda (exn) +inf.0)])
        (/ n d))))

The following example catches and ignores file exceptions, but lets the enclosing context handle breaks:

  (define (file-date-if-there filename)
    (with-handlers ([not-break-exn? (lambda (exn) #f)])
      (file-or-directory-modify-seconds filename)))




[previous] [up] [next]     [index]
Next: Primitive Exceptions Up: Exceptions and Control Flow Previous: Exceptions and Control Flow

PLT