[plt-scheme] thunk-failed? with exceptions
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