eval and DESTROY

Adriano Ferreira a.r.ferreira at gmail.com
Thu Jul 19 12:55:59 BST 2007


On 7/19/07, Matt Lawrence <matt.lawrence at virgin.net> wrote:
> Hello all,
>
> Apologies for veering wildly off-topic.
>
> I've noticed a little edge-case with using block eval to trap fatal
> errors caused by an object going out of the scope of the eval block.
>
> use strict;
> use warnings;
>
> sub DESTROY { die "Foo\n" };
>
> eval { bless {}, 'main' };
> print "1: $@\n";
>
> eval { bless {}, 'main'; 1 };
> print "2: $@\n";
>
> eval { my $foo = bless {}, 'main'; 1; undef $foo };
> print "3: $@\n";
>
>
> I get:
> 1:      (in cleanup) Foo
> 2:
> 3:      (in cleanup) Foo
>
> The weird thing is, changing the second eval to "do" doesn't die and
> does set $@ correctly!
>
> Is die-ing in DESTROY just a bad idea, or is this a bug?

I think this is the known bug reported in the following ticket:

[perl #38513] DESTROY silences failures
https://rt.perl.org/rt3/Ticket/Display.html?id=38513

I've read a lot in perl5-porters about that, but I am not sure about
the current status of the issue.

> Matt

Regards,
Adriano.


More information about the london.pm mailing list