Skip Menu | You are currently an anonymous guest. | Login | Return to Main | About rt.cpan.org
 

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

X Report information
Id: 21612
Status: resolved
Left: 0 min
Priority: 0/0
Queue: Error

Owner: Nobody
Requestors: waba [...] waba.be
Cc:
AdminCc:

Severity: (no value)
Broken in: (no value)
Fixed in: (no value)




X History Display mode: Brief headersFull headers
#   Fri Sep 22 04:58:57 2006 waba[...]waba.be - Ticket created  
Subject: Inconsistent behaviour in rethrow
Date: Fri, 22 Sep 2006 13:58:19 +0200
To: bug-Error[...]rt.cpan.org
From: Thomas Equeter <waba[...]waba.be>
[text/plain 1.7k]
Error version: Error-0.17004
Perl version: v5.8.6
OS version: OpenBSD 3.9 / i386
(but confirmed on other versions/OSes, such as 5.8.8/Linux/amd64).

Most OO languages allow for "exception translation" - that is, catching
an exception, encapsulating the information in an other class and
re-throwing it. Error.pm supports that... but not always!

Generally speaking, using "plain" calls to die is equivalent to throwing
an Error::Simple. Yet, when doing this:

try { die "oops" } otherwise { die "oops2" };

we get:

at /usr/local/libdata/perl5/site_perl/Error.pm line 38.

instead of the expected:

oops2 at -e line 1.

that we get when doing

try { die "oops" } otherwise { throw Error::Simple "oops2" };

Oops. Exception translation works, but only when rethrowing objects.
That's inconsistent...


Some research shows that if the error is correctly detected by Error.pm,
it's mysteriously lost when it comes to rethrowing it. After some more
work, it appears that the following snippet does not do what one might
think:

eval { local $@; die "oops" }; print "no error\n" unless $@;

This was probably unforeseen at the time of writing of version 0.17003,
which introduced this bug with the intend of making the exception
available in $@ in catch/otherwise clauses. Of course the alteration of
this variable was to be as local as possible and resulted in a local
declaration in the eval block.

But since actually we still want to have the modified version of $@
past the eval, the fix is simply to move the local declaration out of
this scope. It will not affect the program logic, as the success of the
eval is determined using its return value ($ok), not $@.


Attached is a patch for the catch and otherwise code, with a testcase
that illustrates the problem.


Best regards,
-Thomas Equeter.

[text/plain 1.5k]
#   Sat Oct 07 06:21:58 2006 SHLOMIF - Correspondence added  
From: SHLOMIF[...]cpan.org
[text/plain 2.1k]
This patch was manually applied in the latest version (0.17006) after
a less optimal fix was applied in 0.17005. Thanks for the fix, the
testcase, and the report!

Regards,

Shlomi Fish

On Fri Sep 22 07:58:57 2006, waba[...]waba.be wrote:
> Error version: Error-0.17004
> Perl version: v5.8.6
> OS version: OpenBSD 3.9 / i386
> (but confirmed on other versions/OSes, such as 5.8.8/Linux/amd64).
>
> Most OO languages allow for "exception translation" - that is,
catching
> an exception, encapsulating the information in an other class and
> re-throwing it. Error.pm supports that... but not always!
>
> Generally speaking, using "plain" calls to die is equivalent to
throwing
> an Error::Simple. Yet, when doing this:
>
> try { die "oops" } otherwise { die "oops2" };
>
> we get:
>
> at /usr/local/libdata/perl5/site_perl/Error.pm line 38.
>
> instead of the expected:
>
> oops2 at -e line 1.
>
> that we get when doing
>
> try { die "oops" } otherwise { throw Error::Simple "oops2" };
>
> Oops. Exception translation works, but only when rethrowing objects.
> That's inconsistent...
>
>
> Some research shows that if the error is correctly detected by
Error.pm,
> it's mysteriously lost when it comes to rethrowing it. After some
more
> work, it appears that the following snippet does not do what one
might
> think:
>
> eval { local $@; die "oops" }; print "no error\n" unless $@;
>
> This was probably unforeseen at the time of writing of version
0.17003,
> which introduced this bug with the intend of making the exception
> available in $@ in catch/otherwise clauses. Of course the alteration
of
> this variable was to be as local as possible and resulted in a local
> declaration in the eval block.
>
> But since actually we still want to have the modified version of $@
> past the eval, the fix is simply to move the local declaration out
of
> this scope. It will not affect the program logic, as the success of
the
> eval is determined using its return value ($ok), not $@.
>
>
> Attached is a patch for the catch and otherwise code, with a
testcase
> that illustrates the problem.
>
>
> Best regards,
> -Thomas Equeter.



#   Sat Oct 07 06:21:59 2006 RT_System - Status changed from 'new' to 'open'  
#   Mon Oct 09 13:00:16 2006 SHLOMIF - Correspondence added  
[text/plain 72b]
Fixed in the trunk and in CPAN with a derivative of the author's
patch.
#   Mon Oct 09 13:00:19 2006 SHLOMIF - Status changed from 'open' to 'resolved'