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
June 27, 2008 08:16
What if $@ was block-local? (was: Re: Why $@ makes me cry)
Message ID:
>>>>> "Paul" == Paul Fenwick <> 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
<> <URL:>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See for Smalltalk and Seaside discussion

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About