Skip to content
Permalink
Browse files

Make `does X::Control` imply throwing to CONTROL

Previously, there was no way to define custom control exceptions. This
provides a way to do so: an exception that `does X::Control` will be
thrown as a control exception, and so seen by CONTROL blocks rather than
CATCH ones.

This space needs a bit more fleshing out generally; none of the existing
CX classes can actually be thrown correctly and just go as CATCH
exceptions (this was already the situation; this change does not make
things worse).
  • Loading branch information...
jnthn committed Jan 12, 2019
1 parent cebf0cb commit ca177e583174c5b5e2dfbde999595d6bc2194343
Showing with 14 additions and 2 deletions.
  1. +13 −1 src/core/Exception.pm6
  2. +1 −1 tools/build/NQP_REVISION
@@ -1,5 +1,6 @@
my role X::Comp { ... }
my class X::ControlFlow { ... }
my role X::Control { ... }

my class Exception {
has $!ex;
@@ -51,7 +52,11 @@ my class Exception {
}

method throw(Exception:D: $bt?) {
$!ex := nqp::newexception() unless nqp::isconcrete($!ex) and $bt;
unless nqp::isconcrete($!ex) and $bt {
my $orig-ex := $!ex;
$!ex := nqp::newexception();
self!maybe-set-control() unless nqp::isconcrete($orig-ex);
}
$!bt := $bt; # Even if !$bt
nqp::setpayload($!ex, nqp::decont(self));
nqp::throw($!ex)
@@ -60,11 +65,18 @@ my class Exception {
unless nqp::isconcrete($!ex) {
$!ex := nqp::newexception();
try nqp::setmessage($!ex, self.message);
self!maybe-set-control();
}
nqp::setpayload($!ex, nqp::decont(self));
nqp::rethrow($!ex)
}

method !maybe-set-control(--> Nil) {
if nqp::istype(self, X::Control) {
nqp::setextype($!ex, nqp::const::CONTROL_ANY);
}
}

method resume(Exception:D: --> True) {
nqp::resume($!ex);
}
@@ -1 +1 @@
2018.12-45-g49f0612
2018.12-59-g2178266

0 comments on commit ca177e5

Please sign in to comment.
You can’t perform that action at this time.