Previous: exceptions errors, Up: exceptions [Contents][Index]
There is limited interoperability between the library (mmck exceptional-conditions) and the
module (chicken condition) bundled with CHICKEN. We achieve it by setting CHICKEN’s
exception handler to raise-continuable at the top level:
(module (demo)
()
(import (scheme)
(mmck exceptional-conditions)
(prefix (chicken condition)
chicken::))
(chicken::current-exception-handler raise-continuable)
#| end of module |# )
or more simply:
(module (demo)
()
(import (scheme)
(mmck exceptional-conditions))
(mmck-exceptional-conditions-setup-interoperability)
#| end of module |# )
Set raise-continuable as current exception handler in the CHICKEN process.
With this setup we can catch exceptions raised with signal using MMCK Exceptional Conditions’s
with-exception-handler:
(define C
(with-exception-handler
;;This handler returns.
(lambda (E) E)
(lambda ()
(chicken::signal
(chicken::make-property-condition 'demo
'location 'me
'message "the message"
'arguments '(1 2 3))))))
(chicken::get-condition-property C 'demo 'location)
⇒ me
(chicken::get-condition-property C 'demo 'message)
⇒ "the message"
(chicken::get-condition-property C 'demo 'arguments)
⇒ (1 2 3)
and we can catch exceptions raised with abort using MMCK Exceptional Conditions’s
with-exception-handler:
(call-with-current-continuation
(lambda (escape)
(with-exception-handler
(lambda (E)
(escape
(list
(chicken::get-condition-property E 'demo 'location)
(chicken::get-condition-property E 'demo 'message)
(chicken::get-condition-property E 'demo 'arguments))))
(lambda ()
(chicken::abort
(chicken::make-property-condition 'demo
'location 'me
'message "the message"
'arguments '(1 2 3)))))))
⇒ (me "the message" (1 2 3))
notice that, due to how abort is defined, if the handler returns we enter an infinite loop,
exactly like it happens with CHICKEN’s with-exception-handler.
It is not possible to handle exceptions raised with raise and
raise-continuable using CHICKEN’s with-exception-handler; however, we can catch
them and convert them:
(call-with-current-continuation
(lambda (escape)
(chicken::with-exception-handler
(lambda (E)
(escape (error? E)))
(lambda ()
(with-exception-handler
chicken::signal
(lambda ()
(raise
(condition
(make-error)
(make-who-condition 'me)
(make-message-condition "the message")
(make-irritants-condition '(1 2 3))))))))))
⇒ #t
Previous: exceptions errors, Up: exceptions [Contents][Index]
This document describes version 0.1.0-devel.1 of MMCK Exceptional Conditions.