Course of Raku / Objects, I/O, and
exceptions / Exceptions / Catching exceptions with try / Exercises / When nothing goes wrong
Solution: When nothing goes wrong
Here is a possible solution to the task.
Code
my $r = try { 21 * 2 };
say $r.defined;
say $r;🦋 You can find the source code in the file try-succeeds.raku.
Output
True
42Comments
When the
tryblock runs without an exception, it simply evaluates to the value of the block.So
$rholds42, and$r.definedisTrue.