You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following code prints got value: (Any) whether an exception occurred or not:
use v6;
my $value = do {
my $result = might-throw();
CATCH {
default {
say "Caught exception: ", .^name;
.resume;
}
}
#my $result = might-throw(); # <-- It works if I move the call to might-throw()
# after the CATCH { ... }
};
say "got value: ", $value;
sub might-throw() {
my $var = <0 1>.pick;
if $var == 0 {
die "Zero is not good!";
-1;
}
else {
1;
}
}
It could be argued that the presence of the CATCH block should not have an effect on what is considered to be the last statement in the do block and hence what becomes the return value of the do block.
This behavior was confirmed by moving the call to migh-throw() after the CATCH { ... } as indicated with the comment in the code above. In this case the program prints got value: -1 or got value: 1 depending on whether an exception occurred or not, as would be expected for a normal do block.
Environment
Operating system: Ubuntu 18.04
Compiler version (perl6 -v): Rakudo version 2018.04.1 built on MoarVM version 2018.04.1
The text was updated successfully, but these errors were encountered:
The following code prints
got value: (Any)
whether an exception occurred or not:It could be argued that the presence of the
CATCH
block should not have an effect on what is considered to be the last statement in thedo
block and hence what becomes the return value of thedo
block.This behavior was confirmed by moving the call to
migh-throw()
after theCATCH { ... }
as indicated with the comment in the code above. In this case the program printsgot value: -1
orgot value: 1
depending on whether an exception occurred or not, as would be expected for a normaldo
block.Environment
perl6 -v
): Rakudo version 2018.04.1 built on MoarVM version 2018.04.1The text was updated successfully, but these errors were encountered: