develooper Front page | perl.perl5.porters | Postings from June 2008

Re: What if $@ was block-local? (was: Re: Why $@ makes me cry)

Thread Previous | Thread Next
From:
Abigail
Date:
June 27, 2008 21:30
Subject:
Re: What if $@ was block-local? (was: Re: Why $@ makes me cry)
Message ID:
20080627155720.GD24356@almanda
On Fri, Jun 27, 2008 at 10:34:05AM -0500, David Nicol wrote:
> >  What would this break?  When are people expecting this to work:
> >
> >      {
> >         eval {
> >              die "foo";
> >         };
> >      }
> >      if ($@) { "expecting foo here"
> >      }
> >
> >  Can we find any of these in the wild?
> 
> I am sure I've done this somewhere, as I often create blocks for no
> purpose other than to scope lexicals, and there's no telling how many
> layers of scope might be between the eval and the checking of $@.
> Also, this is a pattern I've used extensively -- eval within a loop
> and exception handling on the outside, off of the happy path.
> 
>     while (<>){
>         eval {maydie_works_with_topic; 1} or last
>     };
>     do_something_with($@);
> 
> making $@ block-local like $1 is a big change.
> 
> Localizing it (and possibly $? and $!) before calling DESTROY is much
> finer-grained, and should be a four or five line patch to the guts.


Yeah, and I've written code that looks like:

    sub foo {
        ...
        eval {
           ...
        }
    }


    foo;
    if ($@) {
        ...
    }



Abigail

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