Skip to content

Commit

Permalink
added two tests for nested try catch blocks.
Browse files Browse the repository at this point in the history
1) Test returning from a catch block
2) test rethrowing the exception when the inner catch doesn't meet the conditions

Signed-off-by: Ash Berlin <ash_github@firemirror.com>
  • Loading branch information
cesc authored and ashb committed Jul 5, 2009
1 parent 27eddea commit e959db4
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion t/nested.t
@@ -1,6 +1,6 @@
use strict;
use warnings;
use Test::More tests => 4;
use Test::More tests => 6;

BEGIN { use_ok "TryCatch" or BAIL_OUT("Cannot load TryCatch") };

Expand All @@ -24,6 +24,22 @@ sub nested_2 {
is( nested_1(), "from nested_1", "nested try");
is( nested_2(), "from nested_2", "call nested try");

# same thing, but now we return from within the catch
sub nested_catch {
try {
try {
die "Some str\n";
}
catch ( $e ) {
return "caught in nested TC";
}
}

return "didn't catch";
}

is( nested_catch(), "caught in nested TC", "nested catch" );

my $val;
try {
try { die "Foo" }
Expand All @@ -34,3 +50,23 @@ catch ($e) {
}
like($val, qr/^Foo at t[\/\\]nested.t line /,
"Nested try-catch in same function behaves");


# frif: uncatched exceptions should be rethrown
sub nested_rethrow {
try {
try {
die "Some str\n";
}
catch (Str $err where { length $_ < 5 }) {
return "caught in inner TC";
}
}
catch {
return "caught in outer TC";
}

return "didn't catch";
}

is( nested_rethrow(), "caught in outer TC", "nested rethrow" );

0 comments on commit e959db4

Please sign in to comment.