On Tue, Aug 15, 2000 at 06:23:57PM -0600, Tony Olekshy wrote:
> Jonathan Scott Duff wrote:
> > 
> > What's wrong with just using the switch statement?  It seems
> > like except and catch are becoming special-purpose switches
> > to me.  Is it really necessary?
> 
> It's not necessary, but it is the whole point of it all.
> 
> Try is "just" a special-purpose if, except is a special-purpose
> else if, catch is a special-purpose else, as is finally.  Breaking
> the local flow of control in a program is itself special purpose.
> 
> The special-purposeness is that these constructs have unwind
> semantics.  

[ snip ]

> Also note that with manual implementation of exception handling,
> you don't get any unwind-time trace-back debugging info either,
> which RFC 88 does for you.  When you start using this a lot (and
> you will, if Perl 6 goes to internal exceptions for fatal errors),
> you'll quickly find you're glad to have this "special purpose"
> information.

Okay, imagine something for me:

        # some code here that may cause an exception
        exceptions {                    # when thrown, we end up here
            switch ($@->^_) { 
                case canFoo             { ... } # caught if canFoo
                case isa('IOError')     { ... }
                case isa('MathError')   { ... }
                throw $@;               # rethrow unhandled
            }
        }

This "exceptions" block is only entered if an exception is thrown in the
current lexical scope.  Inside the exceptions block we have access to the
exception via $@ and access to the "unwinding information" via some other
special variable that I haven't given a name yet as I'm not exactly
sure what you mean :-)  New keywords added: "throw" and "exceptions".
Semantics supported: ignore unhandled or not (those that wish to
ignore unhandled exceptions just omit the C<throw> at the end of the
switch.)

Now, in the interest of continuing my education, what did I leave out? 

:-)

-Scott
-- 
Jonathan Scott Duff
[EMAIL PROTECTED]

Reply via email to