develooper Front page | perl.perl6.language.errors | Postings from August 2000

Re: RFC 88: What does catch "Foo" { } do?

From:
Tony Olekshy
Date:
August 20, 2000 10:49
Subject:
Re: RFC 88: What does catch "Foo" { } do?
Message ID:
39A019CE.13C8676D@avrasoft.com
Peter Scott wrote:
> 
> Tony Olekshy wrote:
> >
> > Graham Barr wrote:
> > >
> > > I am of the opinion that only a class name should follow catch.
> > > If someone wants to catch based on an expression they should use
> > >
> > >   catch {
> > >     if (<expr>) {
> > >     }
> > >     else {
> > >       # rethrow the error
> > >     }
> > >   }
> >
> > Then you will be glad to know that RFC 88, in the not quite ready
> > version two release, allows you do to just that.
> 
> "Allows" isn't the same as "should be the only way" though.
> 
> Graham, did you base your opinion on usability, parseability, both,
> neither?

And now for a slightly less frisky answer.  The nice thing
about the catch <expr> => <block> form is not necessarily
that you can say things like

    try { ... } catch $@->{severity} =~ /.../ => { ... }

    try { ... } catch grep { $_->isa("Foo") } @@ => { ... }

    try { ... } catch ref $@ =~ /.../ => { ... }

but that within the scope of an application's code you can make
available utility functions to allow really nice phrasing of
rule-based catches (without having to re-raise), such as

        catch not &TooSevere => { ... }

        catch &AnyException("Error::IO") => { ... }

        my $test = sub { lines of predicate based on $@ };

        catch &$test("Foo") => { ... }
        catch &$test("Bar") => { ... }
        ad infinitum

Is there actually a good reason not to allow this functionality?

Yours, &c, Tony Olekshy



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About