Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing semicolon after try/catch not a parse error but strange behaviour #254

Open
Caldrin opened this issue Apr 23, 2013 · 1 comment
Open

Comments

@Caldrin
Copy link

Caldrin commented Apr 23, 2013

When you don't put a semicolon after a try/catch this will not always be reported as an error. Instead, the whole construct is ignored. This can lead to hard to debug errors.

The following example reproduces the issue:

use strict;
use warnings;
use perl5i::2;

func get_foo($foo1, $foo2) {
my $retval = 'UNKNOWN';
try
{
my $info = get_foo_info($foo1);
$retval = get_foo_by_info($info, $foo2);
} catch {
warn $_ if $_;
}
return $retval;
}

func get_foo_by_cpuinfo($info, $foo2) {
return "$info-$foo2";
}

func get_foo_info($foo1) {
return "foo";
}

print get_foo("./","bar");

@schwern
Copy link
Contributor

schwern commented Apr 23, 2013

Sorry about that. It is an unfortunate artifact of how Try::Tiny works (which is what we use for try/catch). try { ... } catch { ... } is actually try( sub { ... }, catch( sub { ... } ) ).

We can chalk this up to another argument for switching to TryCatch which implements proper syntax. See #224

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants