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

Reply via email to