Course of Raku / Objects, I/O, and exceptions / Exceptions / Soft failures / Exercises
A fallback value
Problem
Write a subroutine get that returns its argument, but
calls fail with the message bad when the
argument is 0.
Using the defined-or operator // to provide a fallback
of default, print the result of get(5) and
then of get(0).
Example
The program prints:
5
defaultSolution
Course navigation
← Solution: Lookup or not found | Solution: A fallback value →