develooper Front page | perl.perl5.porters | Postings from July 2013

Re: Try/Catch Exception Objects: Possible?

Thread Previous | Thread Next
From:
David Nicol
Date:
July 26, 2013 22:43
Subject:
Re: Try/Catch Exception Objects: Possible?
Message ID:
CAFwScO80tOSLmwJr=3CHE8N5FU3cVAY2+NA1pc_NX4jG3v9jqA@mail.gmail.com
On Fri, Jul 26, 2013 at 7:07 AM, David E. Wheeler <david@justatheory.com>wrote:

> On Jul 26, 2013, at 1:56 AM, David Nicol <davidnicol@gmail.com> wrote:
>
> >>    package Foo {
> >>        CATCH {
> >>            # BOOM.
> >>        }
> >>    }
> >
> > that looks like it should get optimized out, with a warning: AFAIK
> > Perl has no syntax construct at this time that would change the scope
> > of something depending on if something else is there or not.
> >
> >     package Foo {
> >         CATCH {
> >             ... recovering from Foo:: error ...
> >         }
> >     }
> >     package Foo {
> >         sub riskything{
> >              ...
> >         };
> >         CATCH {
> >             ... recovering from error in Foo::riskything()
> >         }
> >     }
>
> Yeah, that’s what I meant. Should also allow:
>
>     package Foo {
>         use Bar;
>         my $f = Bar->baz;
>         CATCH {
>             # Recover from error anywhere in Foo
>         }
>     }
>

I'm happy I understood you correctly. I think changing the scope of
something based on whether or not enough other stuff appears between the
curlies too is a bad idea, and that the CATCH in the last of the above
examples should only handle tantrums thrown in Bar->baz. Due to the implied
BEGIN around the C<use> the CATCH won't handle tantrums originating in
Bar.pm's inclusion and import, but it should if it precedes it.

Thread Previous | Thread Next


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