[racket] Dirt-simple exceptions

From: Mark Carter (mcturra2000 at yahoo.co.uk)
Date: Sun Sep 5 09:19:29 EDT 2010




----- Original Message ----
> From: Robby Findler <robby at eecs.northwestern.edu>

> (with-handlers ([exn:fail? (lambda (exn)  put-specified-default-here)])
>     try-something-here)

That's the fellow!

Here's a little convenience macro I defined:

(define-syntax catch-errors
  (syntax-rules ()
          ((catch-all error-value body ...)
           (with-handlers ([exn:fail? (lambda (exn) error-value)])
             body ...))))

(catch-errors "Oops" (/ 1 0)) ; "Oops"
(catch-errors "Oops" (/ 6 3)) ; 2
(catch-errors "Oops" (/ 6 3) (/ 16 2)) ; 8



      


Posted on the users mailing list.