Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Defining own CONTROL exception

Tags:

raku

The subject says it all: can I define own control exception which would handled by the CONTROL block? Applying the X::Control role is useless:

 class CX::Whatever does X::Control {
     method message { "<whatever control exception>" }
 }

 do {
     CX::Whatever.new.throw;
     CONTROL {
         say "CONTROL!!!";
         default {
             say "CONTROL: ", $_.WHAT;
         }
     }
 }

By looking into the core sources I could guess that only a predefined set of exceptions is considered suitable for CONTROL, but not sure I didn't miss a thing.

like image 832
Vadim Belman Avatar asked Jan 12 '19 01:01

Vadim Belman


1 Answers

This hasn't been possible in the past, however you're far from the first person to ask for it. Custom control exceptions would provide a way for framework-style things to do internal control flow without CATCH/default in user code accidentally swallowing the exceptions.

Bleeding edge Rakudo now contains an initial implementation of taking X::Control as an indication of a control exception, meaning that the code as you wrote it now does as you expect. This will, objections aside, appear in the 2019.01 Rakudo release, however should be taken as a draft feature until it also appears in a language specification release.

Further, a proposed specification test has been added, so unless there are objections then this feature will be specified in a future Perl 6 language release.

like image 160
Jonathan Worthington Avatar answered Dec 30 '22 11:12

Jonathan Worthington