Reputation: 1210
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.
Upvotes: 6
Views: 111
Reputation: 29454
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.
Upvotes: 8