[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
"bar")))

Thanks,
Pierson

; 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)
  (let
    ((orig-error error) 
     (caught #f))
    (call-with-current-continuation 
     (lambda (cont)
       (set! error ; redefine the error primitive
             (lambda (msg . args)
               ;(cerr "caught error: " msg)
               (set! caught #t)
               (cont #t)))
       (thunk)
       #f))
    (set! error orig-error)
    caught))



__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com



Posted on the users mailing list.