Permalink
Browse files

refactor World.rethrow a bit

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...
1 parent 1d4eb48 commit afe141bda94d3206a0b6f9a6f381a78936fe372e @moritz moritz committed Jul 30, 2012
Showing with 26 additions and 7 deletions.
  1. +22 −7 src/Perl6/World.pm
  2. +4 −0 src/core/Exception.pm
View
@@ -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();
}
}
View
@@ -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

0 comments on commit afe141b

Please sign in to comment.