Skip to content

Commit

Permalink
refactor World.rethrow a bit
Browse files Browse the repository at this point in the history
you can now throw typed exceptions without file/line information, and have World.ex-handle add them for you
previously only untyped exceptions were supported, and wrapped into X::Comp::AdHoc.
arnsholt++ for poking me
  • Loading branch information
moritz committed Jul 30, 2012
1 parent 1d4eb48 commit afe141b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/Perl6/World.pm
Expand Up @@ -1964,16 +1964,31 @@ class Perl6::World is HLL::World {
my $success := 0;
my $ex_t;
my $coercer;
try { $ex_t := self.find_symbol(['X', 'Comp', 'AdHoc']); $success := 1 };
try { $coercer := self.find_symbol(['&COMP_EXCEPTION']); ++$success; };
$err.rethrow unless $success == 2;
my $p6ex := $coercer($err);
nqp::bindattr($p6ex, $ex_t, '$!filename',
nqp::rethrow($err) unless $success;
my $p6ex := $coercer($err);
try {
$ex_t := self.find_symbol(['X', 'Comp']);
if nqp::istype($p6ex, $err) {
$p6ex.SET_FILE_LINE(
nqp::box_s(pir::find_caller_lex__ps('$?FILES'),
self.find_symbol(['Str'])),
nqp::box_i(HLL::Compiler.lineof($/.orig, $/.from),
self.find_symbol(['Int'])),
);
$success++;
}
}
$p6ex.rethrow if $success == 2;
$success := 0;
try { $ex_t := self.find_symbol(['X', 'Comp', 'AdHoc']); ++$success };
$p6ex.rethrow unless $success;
$p6ex.SET_FILE_LINE(
nqp::box_s(pir::find_caller_lex__ps('$?FILES'),
self.find_symbol(['Str'])));
nqp::bindattr($p6ex, $ex_t, '$!line',
self.find_symbol(['Str'])),
nqp::box_i(HLL::Compiler.lineof($/.orig, $/.from),
self.find_symbol(['Int'])));
self.find_symbol(['Int'])),
);
$p6ex.rethrow();
}
}
4 changes: 4 additions & 0 deletions src/core/Exception.pm
Expand Up @@ -313,6 +313,10 @@ my role X::Comp is Exception {
}
$r;
}
method SET_FILE_LINE($file, $line) {
$!filename = $file;
$!line = $line;
}
}

# XXX a hack for getting line numbers from exceptions from the metamodel
Expand Down

0 comments on commit afe141b

Please sign in to comment.