Skip Menu |

This queue is for tickets about the Error CPAN distribution.

Report information
The Basics
Id: 21612
Status: resolved
Priority: 0/
Queue: Error

People
Owner: Nobody in particular
Requestors: waba [...] waba.be
Cc:
AdminCc:

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



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>
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.

Message body is not shown because sender requested not to inline it.

From: SHLOMIF [...] cpan.org
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: Show quoted text
> 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 Show quoted text
> 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 Show quoted text
> 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, Show quoted text
> it's mysteriously lost when it comes to rethrowing it. After some
more Show quoted text
> work, it appears that the following snippet does not do what one
might Show quoted text
> think: > > eval { local $@; die "oops" }; print "no error\n" unless $@; > > This was probably unforeseen at the time of writing of version
0.17003, Show quoted text
> which introduced this bug with the intend of making the exception > available in $@ in catch/otherwise clauses. Of course the alteration
of Show quoted text
> 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 Show quoted text
> this scope. It will not affect the program logic, as the success of
the Show quoted text
> eval is determined using its return value ($ok), not $@. > > > Attached is a patch for the catch and otherwise code, with a
testcase Show quoted text
> that illustrates the problem. > > > Best regards, > -Thomas Equeter.
Fixed in the trunk and in CPAN with a derivative of the author's patch.