Re: "Try? There is no try." -- Yoda's Exception handling syntax

[email protected] (Piers Cawley) 16 Aug 2000 10:35:47 +0100
Newsgroups perl.perl6.language.flow,perl.perl6.language.errors
Message-ID <[email protected]>
Jonathan Scott Duff <[email protected]> writes:

> On Tue, Aug 15, 2000 at 04:12:17PM -0700, Peter Scott wrote:
> > >Would someone please enlighten me as to the purpose of an explicit "try."
> > 
> > Well, for one, it makes it easier to see that a block is subject to 
> > exception handling if all you have to do is look at the beginning for 'try' 
> > rather than scan through it for a 'catch'.
> 
> On Tue, Aug 15, 2000 at 06:24:08PM -0600, Tony Olekshy wrote:
> > The "try" is not necessarily for Perl's sake.  It's for the
> > programmer's sake.  It says, watch out, some sort of non-local
> > flow control may be going on here.  It signals intent to deal
> > with action at a distance (unwinding semantics).
> 
> How important are the exceptions?  What about putting them first?
> 
> 	exceptions { 
> 	   # code that does exception handling
> 	} 
> 	{
> 	   # code that may throw exceptions
> 	}
> 
> Note that's a two-block keyword.


Hm...


    try {
        # this
        throw $that;
    }
    catch It {
        # Do stuff
    }

Has the advantage of reflecting the order in which things may actually
happen, whereas the two block thing doesn't.

-- 
Piers