with-exception-handler -- r7rs Definition procedure;
with-exception-handler (from vonuvoli);Procedure variants:
(((handler exception-handler) (thunk procedure-0)) -> (any))
handler of type exception-handler;thunk of type procedure-0;any;scheme:base -- (scheme base);scheme -- (scheme);(with-exception-handler handler thunk)Domain: It is an error if
handlerdoes not accept one argument. It is also an error ifthunkdoes not accept zero arguments.The
with-exception-handlerprocedure returns the results of invokingthunk.Handleris installed as the current exception handler in the dynamic environment used for the invocation ofthunk.(call-with-current-continuation (lambda (k) (with-exception-handler (lambda (x) (display "condition: ") (write x) (newline) (k 'exception)) (lambda () (+ 1 (raise 'an-error)))))) ===> exception ; and prints: condition: an-error (with-exception-handler (lambda (x) (display "something went wrong\n")) (lambda () (+ 1 (raise 'an-error)))) ; prints: something went wrongAfter printing, the second example then raises another exception.
The text herein was sourced and adapted as described in the "R7RS attribution of various text snippets" appendix.
(call-with-current-continuation
(lambda (k)
(with-exception-handler
(lambda (x)
(display "condition: ")
(write x)
(newline)
(k 'exception))
(lambda ()
(+ 1 (raise 'an-error))))))
condition: an-error
exception
(with-exception-handler
(lambda (x)
(display "something went wrong\n"))
(lambda ()
(+ 1 (raise 'an-error))))
something went wrong