scheme shell
about
download
support
resources
docu
links
 
scsh.net

Safe With Handler

  ;; From the chapter "Condition system" in "The Nearly Complete
  ;; Scheme48 Reference Manual" by Taylor Campbell:
  ;;
  ;;    *Warning:* `With-handler' is potentially very dangerous.  If an
  ;;    exception occurs and a condition is raised in the handler, the
  ;;    handler itself will be called with that new condition!
  ;;    Furthermore, the handler may accidentally return to an unexpecting
  ;;    signaller, which can cause very confusing errors.  Be careful with
  ;;    `with-handler'; to be perfectly safe, it might be a good idea to
  ;;    throw back out to where the handler was initially installed before
  ;;    doing anything.
  ;;
  ;; The following is what he then suggests.

;; ,open handle (define (with-handler/safe handler thunk) ((call-with-current-continuation (lambda (k) (lambda () (with-handler (lambda (kond propagate) (k (lambda () (handler kond propagate)))) thunk))))))


SafeWithHandler - raw wiki source | code snippets archive