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

Quiz — try

What does the following program print?

my $r = try {
    die 'Boom!';
    say 'inside';
};

say 'outside';
1outside
0inside
0inside then outside
0Boom!
0an error

Two things happen here. First, die immediately aborts the rest of the try block, so the say 'inside' line is never reached — nothing is printed from inside the block. Second, because try catches the exception, the program itself does not stop: execution continues past the block, and say 'outside' runs normally. So the only line printed is outside. ($r would be undefined, and the message Boom! would be waiting in $! if you looked.)

Course navigation

Solution: Try or default   |   The CATCH phaser