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:
David Nicol
Date:
June 27, 2008 08:34
Subject:
Re: What if $@ was block-local? (was: Re: Why $@ makes me cry)
Message ID:
934f64a20806270834w12e457d0y84cf91db568236b4@mail.gmail.com
>  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.

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