[plt-scheme] thunk-failed? with exceptions

From: Robert Pierson (fried_flagrum at yahoo.com)
Date: Sat Jun 22 21:31:27 EDT 2002

Hello all,

How can I implement Oleg's thunk-failed? procedure
(below) in PLT that will return #t for things such as 

(thunk-failed? (lambda () (raise-syntax-error 'foo


; Try to execute the thunk, and return #f if execution
; succeeded
; If an error occurred during the execution, it is
; caught, and the thunk-failed? procedure returns #t
(define (thunk-failed? thunk)
    ((orig-error error) 
     (caught #f))
     (lambda (cont)
       (set! error ; redefine the error primitive
             (lambda (msg . args)
               ;(cerr "caught error: " msg)
               (set! caught #t)
               (cont #t)))
    (set! error orig-error)

Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup

Posted on the users mailing list.