On 2012-08-27 07:34:56, CALDRIN wrote:
Show quoted text> When try/catch is used without the semicolon after the catch block, one
> usually gets the unhelpful message:
> Unknown code ref type given ''. Check your usage & try again
> If however the statement following the catch block is a return, no error
> message at all occurs and the whole construct just fails.
>
> Here is an example to reproduce the issue:
> perl -MTry::Tiny -E'sub foo { try { die "The error we expect"} catch
> { die $_ } return} foo(); print "The error we get"'
This isn't really a bug in Try::Tiny, but an annoying facet of perl5. We can't create a control
structure (like if or while) that can end with a brace and no semicolon, so try and catch are
subroutines that expect to be passed a sub and a list of other stuff.
So, you write:
try { 1 } catch { 2 } return
This is interpreted as:
try( sub {1}, catch( sub {2}, return ) )
Obviously, the arguments to `catch` have to be evaluated before it can be called, and evaluating
`return` returns from the subroutine.
While I sympathize with you — this is really annoying — it's not something that I think Try::Tiny
can fix. You might like Try.pm, which trades away the required semicolon for a different set of
constraints.
Please let me know if you think there's some other solution that I can't see.
--
rjbs