Permalink
Browse files

Fix nested test error reported by Possum

  • Loading branch information...
1 parent 4a898d8 commit d3e0903f547c2fbf06855761cd8460faf6c52af6 @ashb committed May 13, 2009
Showing with 13 additions and 7 deletions.
  1. +3 −0 Changes
  2. +6 −4 lib/TryCatch.pm
  3. +4 −3 t/nested.t
View
@@ -1,5 +1,8 @@
Version history for TryCatch perl module:
+ - Fix bug with nested try+die (Reported by Possum)
+ As a result of this $@ will not have the value of the exception visible
+
1.001000 - 2009/04/26 - 01:01
- Fix bug where catch block would get run sometimes when it shouldn't
- Better error reporting
View
@@ -67,7 +67,7 @@ sub check_tc {
# From here on out its parsing methods.
-# Replace 'try {' with an 'try (sub {'
+# Replace 'try {' with an 'try; { local $@; eval {'
sub _parse_try {
my $pack = shift;
@@ -116,7 +116,7 @@ sub injected_try_code {
sub injected_after_try {
# This semicolon is for the end of the eval
- return '; if ($@) { local $TryCatch::Error = $@;';
+ return ';$TryCatch::Error = $@; } if ($TryCatch::Error) { ';
}
sub injected_no_catch_code {
@@ -164,7 +164,7 @@ sub block_postlude {
} else {
my $code = $STATE[-1] == 0
? $ctx->injected_no_catch_code
- : '}}';
+ : '}';
substr($linestr, $offset, 0, $code);
@@ -300,8 +300,10 @@ TryCatch - first class try catch semantics for Perl, without source filters.
use TryCatch;
sub foo {
+ my ($self) = @_;
+
try {
- # some code that might die
+ die Some::Class->new(code => 404 ) if $self->not_found;
return "return value from foo";
}
catch (Some::Class $e where { $_->code > 100 } ) {
View
@@ -27,9 +27,10 @@ is( nested_2(), "from nested_2", "call nested try");
my $val;
try {
try { die "Foo" }
- catch ($e) { die "$e\n" }
+ catch ($e) { die "$e" }
}
catch ($e) {
- $val = "$e\n";
+ $val = "$e";
}
-like($val, qr/^Foo at line /, "Double nested try-catch behaves");
+like($val, qr/^Foo at t[\/\\]nested.t line /,
+ "Nested try-catch in same function behaves");

0 comments on commit d3e0903

Please sign in to comment.