Course of Raku / Objects, I/O, and exceptions / Exceptions / Catching exceptions with try / Exercises

Try or default

Problem

A try block that fails evaluates to an undefined value. Use this with the defined-or operator // to supply a fallback: run a try block that does die 'no', and if it fails, use the string default instead. Print the result.

Example

The program prints:

default

Solution

See the solution

Course navigation

Solution: When nothing goes wrong   |   Solution: Try or default