role X::Control is Exception { }

This role turns an exception into a control exception, such as CX::Next or CX::Take. It has got no code other than the definition.

Since Rakudo 2019.03, throwing an object that mixes in this role X::Control can raise a control exception which is caught by the CONTROL phaser instead of CATCH. This allows to define custom control exceptions.

For example, the custom CX::Oops control exception we define below:

class CX::Vaya does X::Control {
    has $.message
}
 
sub ea {
    CONTROL {
        default {
            say "Controlled { .^name }{ .message }"
        }
    }
    CX::Vaya.newmessage => "I messed up!" ).throw;
 
}
ea;
# OUTPUT: «Controlled CX::Vaya: I messed up!␤» 

Typegraph§

Type relations for X::Control
raku-type-graph X::Control X::Control Exception Exception X::Control->Exception Mu Mu Any Any Any->Mu Exception->Any CX::Next CX::Next CX::Next->X::Control CX::Next->Exception CX::Last CX::Last CX::Last->X::Control CX::Last->Exception CX::Succeed CX::Succeed CX::Succeed->X::Control CX::Succeed->Exception CX::Proceed CX::Proceed CX::Proceed->X::Control CX::Proceed->Exception CX::Return CX::Return CX::Return->X::Control CX::Return->Exception CX::Take CX::Take CX::Take->X::Control CX::Take->Exception CX::Redo CX::Redo CX::Redo->X::Control CX::Redo->X::Control CX::Redo->Exception CX::Redo->Exception CX::Emit CX::Emit CX::Emit->X::Control CX::Emit->Exception CX::Warn CX::Warn CX::Warn->X::Control CX::Warn->Exception CX::Done CX::Done CX::Done->X::Control CX::Done->Exception

Expand chart above