[plt-scheme] exception handling

From: Dave Griffiths (dave at pawfal.org)
Date: Tue Jan 20 07:31:12 EST 2009

Hi all,

A quick question about exception handling. I'd like to run a thunk in a
context where I can capture the error and do something with it in code -
i.e. keep the program running after the error has occurred. For example
something like this:

(define error-happened #f)

(define (err n)
  (set! error-happened #t))

(call-with-exception-handler err (lambda () (modulo 0 1 2)))

(when error-happened
  (do-something))

However, the value of (err) is passed to the uncaught exception handler,
which in turn stops evaluation. I certainly don't want to turn off the
normal exception handling globally, so I'm guessing I can use
(with-handlers) but I'm not sure how.

cheers,

dave



Posted on the users mailing list.