In the process of writing some more tests for CATCH blocks, I've noticed
what appears to be a contradiction between Synopsis 4 on the one hand
and pugs/t/spec/S04-statements/try.t and Rakudo's current behavior on
the other. The specification says "there is an implicit C<die $!> just
inside the end of the C<CATCH> block", and that if you want to catch an
exception you haven't explicitly smart-matched, you need to use a
C<default> block. But look at this test:
{
# try with a catch
my $caught;
try {
die "blah";
CATCH { $caught = 1 }
};
ok($caught, "exception caught");
};
The "blah" ought to be rethrown by the CATCH block, avoiding the ok()
entirely, but instead, Rakudo passes this test. Is this a mistake on the
part of the test and the implementation, or on the part of the
specification? It confuses matters that CATCH is defined to act like a
switch statement, and
given EXPR { default { ... } }
is the same as
given EXPR { ... }
, making C<default> strictly redundant in given blocks but not
(according to the spec) CATCH blocks.