- fix (fsvo) broken URLs (RT#55659)
- proper exception on erroneous usage of bare catch/finally (RT#81070)
- proper exception on erroneous use of multiple catch{} blocks
+ - clarify exception occuring on unterminated try block (RT#75712)
0.12
- doc fixes
# find labeled blocks in the argument list.
# catch and finally tag the blocks by blessing a scalar reference to them.
foreach my $code_ref (@code_refs) {
- next unless $code_ref;
- my $ref = ref($code_ref);
-
- if ( $ref eq 'Try::Tiny::Catch' ) {
+ if ( ref($code_ref) eq 'Try::Tiny::Catch' ) {
croak 'A try() may not be followed by multiple catch() blocks'
if $catch;
$catch = ${$code_ref};
- } elsif ( $ref eq 'Try::Tiny::Finally' ) {
+ } elsif ( ref($code_ref) eq 'Try::Tiny::Finally' ) {
push @finally, ${$code_ref};
} else {
- confess("Unknown code ref type given '${ref}'. Check your usage & try again");
+ croak(
+ 'try() encountered an unexpected argument ('
+ . ( defined $code_ref ? $code_ref : 'undef' )
+ . ') - perhaps a missing semi-colon before or'
+ );
}
}
use strict;
use warnings;
-use Test::More tests => 5;
+use Test::More tests => 6;
use Try::Tiny;
sub _eval {
try { 1 } catch { 2 } catch { 3 } finally { 4 } finally { 5 }
} qr/\QA try() may not be followed by multiple catch() blocks/, 'Multi-catch detected';
+
+throws_ok {
+ try { 1 } catch { 2 }
+ do { 2 }
+} qr/\Qtry() encountered an unexpected argument (2) - perhaps a missing semi-colon before or at/,
+ 'Unterminated try detected';