Exceptions: Difference between revisions

m
→‎{{header|Raku}}: Fix link and commet: Perl 6 --> Raku
(Rename Perl 6 -> Raku, alphabetize, minor clean-up)
m (→‎{{header|Raku}}: Fix link and commet: Perl 6 --> Raku)
Line 2,643:
(formerly Perl 6)
{{works with|rakudo|2015-09-10}}
The Perl 6Raku 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.
<lang perl6>try {
die "Help I'm dieing!";
Line 2,670:
</pre>
 
Perl 6Rake comes with [http://design.perl6raku.org/S04.html#Phasers phasers], that are called when certain conditions in the life of a program, routine or block are met. <tt>CATCH</tt> is one of them and works nicely together with <tt>LEAVE</tt> 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.
 
<lang perl6>sub f(){
2,392

edits