[comp.lang.scheme] Exception handling - how to define it ?

bevan@cs.man.ac.uk (Stephen J Bevan) (03/29/91)

What is the general style used to write exceptions and their handlers
in Scheme?  By exceptions I mean facilities similar to catch/throw in
Lisp.  The ways I can see of doing it are :-

1) Pass a success and fail continuation to every function.

2) Pass multiple continuations, one for each error to be handled.

3) Call a function that is assumed to be set by the user e.g.
 
     (define (foo x y z)
       ...
       (if (some-unexpected-error)
         (unexpected-error-exception args) ...))

   where `unexpected-end-of-file-exception' as a default just aborts.
   It would be up the user to re-define this as appropriate.  I guess
   the easiest way of doing this would be via fluid-let e.g. :-

      (fluid-let ((unexpected-error-exception
                    (lambda x (do-something-sensible x))))
        (foo an-arg another-arg yet-another-arg))

   However, as fluid-let isn't part of the standard (as far as I'm
   aware), this solution isn't portable.

So some questions :-

* Are there better mechanisms that those above?
* Any opinons as to which is the best?
* Am I totally of course trying to use exceptions in Scheme?

All answers greatefully received.

Stephen J. Bevan			bevan@cs.man.ac.uk