Revision history for Try-Tiny
{{$NEXT}}
+ - also throw an exception for catch/finally in scalar context (RT#81070)
0.13 2013-07-04
- fix tests failing on 5.6.x due to differing DESTROY semantics
sub catch (&;@) {
my ( $block, @rest ) = @_;
- croak 'Useless bare catch()' unless defined wantarray;
+ croak 'Useless bare catch()' unless wantarray;
return (
bless(\$block, 'Try::Tiny::Catch'),
sub finally (&;@) {
my ( $block, @rest ) = @_;
- croak 'Useless bare finally()' unless defined wantarray;
+ croak 'Useless bare finally()' unless wantarray;
return (
bless(\$block, 'Try::Tiny::Finally'),
use strict;
use warnings;
-use Test::More tests => 6;
+use Test::More tests => 8;
use Try::Tiny;
do { 2 }
} qr/\Qtry() encountered an unexpected argument (2) - perhaps a missing semi-colon before or at/,
'Unterminated try detected';
+
+sub foo {
+ try { 0 }; catch { 2 }
+}
+
+throws_ok {
+ if (foo()) {
+ # ...
+ }
+} qr/\QUseless bare catch/,
+ 'Bare catch at the end of a function call';
+
+sub bar {
+ try { 0 }; finally { 2 }
+}
+
+throws_ok {
+ if (bar()) {
+ # ...
+ }
+} qr/\QUseless bare finally/,
+ 'Bare finally at the end of a function call';