sunterlib/scsh/interaction/inspect-exception.scm

55 lines
2.2 KiB
Scheme
Raw Normal View History

2003-01-28 08:44:57 -05:00
;;; This file is part of the Scheme Untergrund Library.
;;; Copyright (c) 2002-2003 by Martin Gasbichler.
;;; For copyright information, see the file COPYING which comes with
;;; the distribution.
;; From SUnet plus one more call/cc to capture the continuation of the error
2003-04-23 05:21:30 -04:00
(define (with-fatal-and-capturing-error-handler handler thunk)
2003-01-28 08:44:57 -05:00
(call-with-current-continuation
(lambda (accept)
((call-with-current-continuation
(lambda (k)
(with-handler
(lambda (condition more)
(primitive-cwcc
(lambda (raw-condition-continuation)
(call-with-current-continuation
(lambda (condition-continuation)
(call-with-current-continuation
(lambda (decline)
(k (lambda ()
(handler condition raw-condition-continuation
condition-continuation decline)))))
(more)))))) ; Keep looking for a handler.
(lambda () (call-with-values thunk accept)))))))))
2003-01-28 08:44:57 -05:00
(define (with-inspecting-handler port prepare thunk)
2003-04-23 05:21:30 -04:00
(with-fatal-and-capturing-error-handler
(lambda (condition raw-condition-continuation condition-continuation more)
(with-handler
(lambda (condition-continuation ignore)
(more))
(if (prepare condition)
(let ((res
(remote-repl "Welcome to the command processor of the remote scsh"
raw-condition-continuation
port)))
;; TODO: option to return to continuation of handler
;; (by leaving out this call)
(condition-continuation res))
(more))))
thunk))
2003-04-23 05:21:30 -04:00
(define display-preview (eval 'display-preview
(rt-structure->environment (reify-structure 'debugging))))
(define (display-continuation continuation . maybe-port)
(let ((out (if (null? maybe-port)
(current-output-port)
(car maybe-port))))
(if continuation
(display-preview (continuation-preview continuation)
out)
(display 'bottom-contination out))))