Course of Raku / Objects, I/O, and exceptions / Exceptions / Exception objects / Exercises / Name the error
Solution: Name the error
Here is a possible solution to the task.
Code
sub risky {
die 'sub failed';
}
{
risky();
CATCH {
default {
say .^name;
say .message;
}
}
}🦋 You can find the source code in the file name-the-error.raku.
Output
X::AdHoc
sub failedComments
The
diehappens insiderisky, but the exception travels up to the caller. TheCATCHin the block that calledriskyhandles it, which is how error handling normally works: the failure and its handler need not be in the same routine.A plain
diewith a string creates anX::AdHocexception, which.^namereports, and.messagereturns the text that was passed todie.
Course navigation
← Name the error | Match the type →