Course of Raku / Objects, I/O, and
exceptions / Exceptions / Catching exceptions with try / Exercises
Catch the error
Problem
Show both sides of try. First, use a try
block around a calculation that succeeds (for example
6 * 7) and print its result. Then use a second
try block around code that does die 'broken';
print whether that block produced a defined result, and print the
message of the caught exception.
Example
The program prints:
42
False
brokenSolution
Course navigation
← Not every error is immediate | Solution: Catch the error →