[racket] Dirt-simple exceptions
----- 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