Skip Menu |
 

This queue is for tickets about the Error CPAN distribution.

Report information
The Basics
Id: 38836
Status: rejected
Worked: 20 min
Priority: 0/
Queue: Error

People
Owner: SHLOMIF [...] cpan.org
Requestors: EDAVIS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 0.17012
Fixed in: (no value)



Subject: Strange message if eval {} used in destructor
Download (untitled) / with headers
text/plain 868b
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.
Subject: Re: [rt.cpan.org #38836] Strange message if eval {} used in destructor
Date: Fri, 29 Aug 2008 14:03:18 -0500
To: bug-Error [...] rt.cpan.org
From: Graham Barr <gbarr [...] pobox.com>
Download (untitled) / with headers
text/plain 436b
On Aug 29, 2008, at 4:29 AM, EDAVIS via RT wrote: Show quoted text
> 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
This is a know perl issue and not specific to the Error module If you intend to use eval in a DESTROY, then put local $@ at the start of the sub Graham.
Download (untitled) / with headers
text/plain 317b
Show quoted text
>This is a know perl issue and not specific to the Error module
Yes it is a known issue... I just wondered if Error could perform some magic ju-ju to get around it. If not, then the answer is simply to use Error and try {} everywhere and avoid eval {}, since putting try {} in a DESTROY function seems to work okay.
Nothing we can do about it, so closing as invalid. Regards, -- Shlomi Fish


This service is sponsored and maintained by Best Practical Solutions and runs on Perl.org infrastructure.

Please report any issues with rt.cpan.org to rt-cpan-admin@bestpractical.com.