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

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

Thread Previous | Thread Next
From:
merlyn
Date:
June 27, 2008 08:16
Subject:
What if $@ was block-local? (was: Re: Why $@ makes me cry)
Message ID:
86lk0qzz52.fsf_-_@blue.stonehenge.com
>>>>> "Paul" == Paul Fenwick <pjf@perltraining.com.au> writes:

Paul> I'm actually happy with *any* suggestion that guarantees that $@ gets set
Paul> after a failed eval {}, which is what the documentation generally says will
Paul> happen.  Whether $@ decides to subsequently clear itself (or stupidly
Paul> evaluates to false) doesn't concern me.

What if $@ was handled similarly to $1, made block local?

Clearly, "die" in an eval block is setting the value of $@ *outside* the
enclosing eval.  But having a die inside an eval {} inside a block would be
setting the $@ for only that block, leaving any outer setting untouched.

This automatically handles the DESTROY problem, since that's a new block.

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?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion

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