Course of Raku / Objects, I/O, and exceptions / Exceptions / Exception objects / Exercises / Prefix the message

Solution: Prefix the message

Here is a possible solution to the task.

Code

{
    die 'timeout';

    CATCH {
        default {
            say 'Error: ' ~ .message;
        }
    }
}

🦋 You can find the source code in the file error-prefix.raku.

Output

Error: timeout

Comments

  1. The exception object’s .message gives the text passed to die.

  2. Concatenating it after Error: builds the final line. The exception object is just a value, so you can use its message however you like.

Course navigation

Prefix the message   |   Quiz — Exception objects