Permalink
Browse files

A more HLL approach to handling exceptions in END

The original code was sorta cargo-culted from NQP at the time.
Having it in HLL code means we can also handle exceptions at this
point in time in HLL code.  Also it seemed like a good idea to not
have one END block's exception blow it for all of the other ones.
Finally, give a summary of execution errors that occurred when done.
  • Loading branch information...
lizmat committed Nov 14, 2017
1 parent be9e19e commit 142c1d657cf005254f0feb495dedc497bba21375
Showing with 11 additions and 6 deletions.
  1. +11 −6 src/core/Rakudo/Internals.pm
@@ -1535,20 +1535,25 @@ my constant $?BITS = nqp::isgt_i(nqp::add_i(2147483648, 1), 0) ?? 64 !! 32;
unless $the-end-is-done {
$the-end-locker.protect: {
unless $the-end-is-done {
my $comp := nqp::getcomp('perl6');
my $end := nqp::getcurhllsym('@END_PHASERS');
my $end := nqp::getcurhllsym('@END_PHASERS');
my @exceptions;
while nqp::elems($end) { # run all END blocks
my $result := nqp::shift($end)();
$result.sink if nqp::can($result,'sink');
CATCH { $comp.handle-exception($_) }
CONTROL { $comp.handle-control($_) }
quietly {
my $result := nqp::shift($end)();
$result.sink if nqp::can($result,'sink');
CATCH { default { @exceptions.push($_) } }
}
}
#?if moar
# close all open files
IO::Handle.^find_private_method(
'close-all-open-handles'
)(IO::Handle);
#?endif
if @exceptions {
note "Some exceptions where thrown in END blocks:";
note " $_.^name(): $_.message()" for @exceptions;
}
nqp::not_i(($the-end-is-done = 1)); # we're really done now
}
}

1 comment on commit 142c1d6

@MasterDuke17

This comment has been minimized.

Show comment
Hide comment
@MasterDuke17

MasterDuke17 Nov 14, 2017

Contributor

Typo, "where" -> "were"

Contributor

MasterDuke17 commented on 142c1d6 Nov 14, 2017

Typo, "where" -> "were"

Please sign in to comment.