Subject: | Strange message if eval {} used in destructor |
Suppose a class has a DESTROY method and that uses eval {} to trap an
error. Then if you construct an object of that class inside a try {}
block which dies, the error message is lost. Instead you get something like
at /usr/lib/perl5/vendor_perl/5.10.0/5.10.0/Error.pm line 38.
Is it possible to preserve the original error message in such cases?
#!/usr/bin/perl
use warnings;
use strict;
use 5.010;
use Error qw(:try);
package X;
use Error qw(:try);
sub new {
my $class = shift;
return bless {}, $class;
}
sub DESTROY {
eval { 0 };
}
package main;
try {
my $x = new X;
die 'urk';
}
except {
my $E = shift;
say "error: $E";
}
Expected output: should give the original message 'urk'.
Actual output:
at /usr/lib/perl5/vendor_perl/5.10.0/5.10.0/Error.pm line 38.
error: at /usr/lib/perl5/vendor_perl/5.10.0/5.10.0/Error.pm line 38.