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

Re: local $@ has an unwanted side effect

Thread Previous | Thread Next
Mark Mielke
March 21, 2008 11:00
Re: local $@ has an unwanted side effect
Message ID:
Jan Dubois wrote:
>> I suggest that $@ should be automatically preserved across (localised
>> to) DESTROY functions, and in the absence of such a change to the core
>> I have argued for all DESTROY functions to explicitly localise $@ and
>> the other global status variables.
> I would find this an acceptable change for 5.12 (with a corresponding
> warning in 5.10.1 docs).
> If we can't agree on doing that, then a somewhat reasonable compromise
> might be to only localize $@ during the processing of a die() call
> itself. That way any additional exceptions thrown by destructors won't
> overwrite the original exception

If the behaviour absolutely must change in Perl 5 (perhaps 
insignificant, but I do not agree - small border cases that go 
undiscovered or at least uncomplained about for over a decade, does not 
seem to be something that absolutely must change), I believe the true 
problem here is that die seems to be pass by reference, and that local 
is restoring the value to undef (or whatever it was before) before $@ is 
made available to the caller.

Talking about automatically localizing of $@ during DESTROY, although 
useful, is not related to the original complaint. The original complaint 
was that local causes a problem. Automatic localization does not fix the 
problem - it propagates it. Other people are bringing up other failures 
of the Perl 5 exception model (their own peaves?) and twisting them 
together, in what can only be summarized as "why Perl 5 exceptions 
suck." I've known they sucked for a long time, and I accept it. Fixing 
one place here, fixing one place there, and eventually you have 
something that WILL break existing Perl 5 code. It might be great - but 
if existing programs start to fail, whose fault is it?


Mark Mielke <>

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