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

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

January 26, 2005 12:25
Re: [perl #33940] Interrelations of DESTROY and eval are not welldocumented
Message ID:
In article <>,
	"Victor Porton,,," (via RT) <> 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. Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About