Exceptions
The Raku equivalent to Perl 5's eval {...} is try {...}. A try block by default has a CATCH block that handles all fatal exceptions by ignoring them. If you define a CATCH block within the try, it replaces the default CATCH. It also makes the try keyword redundant, because any block can function as a try block if you put a CATCH block within it. The inside of a CATCH functions as a switch statement on the current exception.
Output:
Rake comes with phasers, that are called when certain conditions in the life of a program, routine or block are met. CATCH
is one of them and works nicely together with LEAVE
that is called even if an exception would force the current block to be left immediately. It's a nice place to put your cleanup code.
Output:
Last updated