Skip to content

Commit

Permalink
Remove warning from using try at package level
Browse files Browse the repository at this point in the history
  • Loading branch information
ashb committed Mar 26, 2009
1 parent beaf01d commit 55fea7c
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/TryCatch/Exception.pm
Expand Up @@ -47,7 +47,7 @@ sub run {
local $CTX = $CTX;

my ($package) = caller(1);
if ($package eq __PACKAGE__) {
if (defined $package && $package eq __PACKAGE__) {
# nested: try { try {} }
die "Internal Error: Nested try without CTX" unless defined $CTX;
} else {
Expand Down
3 changes: 3 additions & 0 deletions t/simple.t
Expand Up @@ -39,6 +39,8 @@ is(simple_no_return(), "bar", "try without explicity return");
is(use_test(), 42, "use in try block");

my $ran_catch = 0;
my $warnings = 0;
$SIG{__WARN__} = sub { $warnings++; CORE::warn(@_) };

try {
foo();
Expand All @@ -47,6 +49,7 @@ catch ($e) {
$ran_catch = 1;
}
is($ran_catch, 0, "Catch block not run");
is($warnings, 0, "No warnings from try in not in sub");

sub foo {
return 1;
Expand Down

0 comments on commit 55fea7c

Please sign in to comment.