| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This layer provides SRFI-18 compatible simple exception mechanism.
You can override the behavior of higher-level constructs such as
with-error-handler by using with-exception-handler.
Note that it is a double-edged sword. You'll get a freedom to construct your own exception handling semantics, but the Gauche system won't save if something goes wrong. Use these primitives when you want to customize the system's higher-level semantics or you are porting from other SRFI-18 code.
<exception> class.
Combined with with-exception-handler you can give your own
semantics to the exception.
raise returns whatever the handler returns.
Generally, if you want to handle non-continuable exception such as
errors using this low-level mechanism,
you have to transfer the control from the handler explicitly
(See the explanation of with-error-handler above).
raise detects if the handler returns on the
non-continuable exceptions and reports an error using the
default error handler mechanism, but it is just a safety net.
Note also that handler is called in the same dynamic environment
of raise. So if you raise an exception inside handler,
it is captured by handler again. It is the programmer's
responsibility to propagate the exception handling to the "outer"
exception handlers.
The behavior of those procedures can be explained in the following conceptual Scheme code.
;; Conceptual implementation of low-level exception mechanism.
;; Suppose %xh is a list of exception handlers
(define (current-exception-handler) (car %xh))
(define (raise exn)
(receive r ((car %xh) exn)
(when (uncontinuable-exception? exn)
(set! %xh (cdr %xh))
(raise (make-error "returned from uncontinuable exception")))
(apply values r)))
(define (with-exception-handler handler thunk)
(let ((prev %xh))
(dynamic-wind
(lambda () (set! %xh (cons handler)))
thunk
(lambda () (set! %xh prev)))))
|
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |