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 25, 2013 23:56
Subject:
Re: Try/Catch Exception Objects: Possible?
Message ID:
CAFwScO85OUjWSZoiM-EM-Wy1EF=DLV-vE2_ww17_W_ZQ6Mzuyw@mail.gmail.com
On Thu, Jul 25, 2013 at 2:07 PM, David E. Wheeler <david@justatheory.com> wrote:
> On Jul 25, 2013, at 7:34 PM, David Nicol <davidnicol@gmail.com> wrote:
>
>> With that use case in mind, having a package catch scope might be good
>
> Don’t we have a package scope since 5.14 or so if you use a block?
>
>     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()
         }
     }


Another question -- where does a package-scoped Catch return its value
to? -- I imagine the answer would be, at the call stack boundary
between the package that caught the error and a different package that
called it.

That would support conventions such as returning -1 for errors
implemented like so:

    FancyNewNetworkLibrary::CATCH { warn "unhandled exception ".shift @@; -1 }

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