develooper Front page | perl.perl5.porters | Postings from January 2005

Re: [perl #33940] Interrelations of DESTROY and eval are not welldocumented

From:
perl5-porters
Date:
January 26, 2005 12:25
Subject:
Re: [perl #33940] Interrelations of DESTROY and eval are not welldocumented
Message ID:
ct8uaa$ena$1@post.home.lunix
In article <rt-3.0.11-33940-106489.16.0611746958661@perl.org>,
	"Victor Porton,,," (via RT) <perlbug-followup@perl.org> writes:
> I reasonably detailed scanned perlobj, perltoot, perlbot manpages,
> read "die" and "eval" entries in perlfunc and found no answer.
> 
> The questions answer to which seems missing in Perl docs is:
> 
> Consider code:
> 
> eval {
>   my $obj1 = Class1->new;
>   {
>     my $obj2 = Class2->new;
>     # Suppose Class2->DESTROY calls 'die "2"'
>   }
>   # Suppose Class1->DESTROY also 'die "1"'
> }
> 
> What is now $@?
> 
> I'd like if ($@ eq "1") after this eval block (outer object to allow
> to override inner exception), but I found no warranty for ($@ eq "1")
> in Perl docs.
> 
Sorry, it won't do what you want exactly.

dies in DESTROY append "\t(in cleanup)error message" to the existing $@.
It's documented in a rather obscure place, in perlcall under G_KEEPERR, 
and rather sideways even there. (you need to read rather carefully to infer 
it will happen for die in DESTROY) 
And it has some weird, undocumented and broken trickery to try to avoid 
duplicate messages too.

I agree with you that it deserves a more highlevel explanation in a more
visible place.



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About