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

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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About