Chaim Frenkel <[EMAIL PROTECTED]> writes:

> One thing that isn't addressed in any of the exception RFC's (and it
> may not be appropriate) is how to actually use it. Not in the syntactical
> or semantic meaning. But in how to use it practically.
> 
> Given six lines of code within a trapping context, how does one
> end up with the invariant restored at the end of the trapping context?
> 
> What in the perl6 helps me to maintain invariants? If the proposed
> mechanism doesn't help me to accomplish this, then all we've done is
> add more text and complexity and we should leave it be.
> 
> (Many moons ago, I developed a set of macros to do exceptions. And
> during the course of use, I found I had to order my code, so that
> invariants were maintained, in the face of exceptions (basically
> longjmps around my code.)
> 
> Anything else, ended up with segfaults at the worst times.
> )

I would hope that our syntax would allow us to do something like:

    try {
        #
    }
    catch Exception::Foo {
        # Do stuff
    }
    catch Exception {
        # Default exception handling.
        $@->handle
    }
    continue|always|finally|whatever {
        # Restore the invariant
    }

Note that under this proposal we can take advantage of polymorphism
and replace the 'else/otherwise' clause with a simple catch on the
Exception parent class, though this does presuppose that all
Exceptions will inherit from this class.

The (continue|always|finally|whatever) clause will *always* be
executed, even if one of the catch clauses does a die, so you can use
this to roll back the database transaction or whatever else was going
on and restore any invariants.

Note too that we don't need to do any case based magic, we can and
should use polymorphism for that.

-- 
Piers
#!perl -w -Mstrict
'063039183598121887134041122600:1917131105:Jaercunrlkso tPh.'=~/^(.{6})*
(.{6})[^:]*:(..)*(..).*:(??{'.{'.$2%$4.'}'})(.)(??{print$5})/x;print"\n"

Reply via email to