On 16-Jun-1998, Greg Michaelson <[EMAIL PROTECTED]> wrote:
> In SML(sorry...), in: <exp1> handle <exp2>
> <exp1> is evaluated and any exception raised within it is handled by an
> appropriate handler in <exp2>. If there isn't one then the exception
> is handled in the enclosing environment for the whole construct. Similarly,
> if an exception is raised in <exp2> then it is handled in the enclosing
> environment. So exception handling follows a stack based regime.
> 
> Instead, how about having <exp2> handle exceptions raised within itself 

You can do this quite easily:

        expr1 `recursive_handle` expr2 =
                expr1 `handle` (\ e -> expr2 e `recursive_handle` expr2)

(Here I'm using a version of `handle' where the handler is the 2nd argument.)

However, doing this might be a bad idea, I think, because if `expr2'
raises any exception, this could easily lead to an infinite loop.

> and also allowing mutually recursive handlers?

This is also allowed by the current proposal -- it's quite straightforward:

        handler1 e = stuff1 `handle` handler2
        handler2 e = stuff2 `handle` handler1

-- 
Fergus Henderson <[EMAIL PROTECTED]>  |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>  |  of excellence is a lethal habit"
PGP: finger [EMAIL PROTECTED]        |     -- the last words of T. S. Garp.


Reply via email to