=begin pod :kind("Type") :subkind("class") :category("exception")

=TITLE role X::Control

=SUBTITLE Role for control exceptions

    role X::Control is Exception { }

This role turns an exception into a
L<control exception|/language/exceptions#Control_exceptions>, such as
C<CX::Next> or C<CX::Take>. It has got no code other than the definition.

Since Rakudo 2019.03, C<throw>ing an object that mixes in this role
C<X::Control> can raise a control exception which is caught by the L<CONTROL
phaser|/language/phasers#CONTROL> instead of L<CATCH|/language/phasers#CATCH>.
This allows to define custom control exceptions.

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

=begin code
class CX::Vaya does X::Control {
    has $.message
}

sub ea {
    CONTROL {
        default {
            say "Controlled { .^name }: { .message }"
        }
    }
    CX::Vaya.new( message => "I messed up!" ).throw;

}
ea;
# OUTPUT: «Controlled CX::Vaya: I messed up!␤»
=end code

=end pod
