Skip to content

Instantly share code, notes, and snippets.

@moritz
Created August 1, 2011 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save moritz/1118213 to your computer and use it in GitHub Desktop.
Save moritz/1118213 to your computer and use it in GitHub Desktop.
Exception prototoype
multi sub my-die(Mu $class, *%params) {
my Mu $p6ex = $class.new(|%params);
my Mu $parrot_ex := pir::new__PS('Exception');
pir::setattribute__vPsP($parrot_ex, 'payload', $p6ex);
pir::throw__vP($parrot_ex);
1;
};
say 'alive';
my $thing;
try {
my-die(X::Base, message => 'Foo!');
CATCH { $thing = $!; }
}
# the getattr is necessary because rakudo atuomaticall wraps
# the parrot exception in an Exception object
my $parrot_ex := nqp::getattr(pir::perl6_decontainerize__PP($thing), Exception, '$!ex');
pir::say(pir::typeof($parrot_ex));
my $ex = nqp::atkey($parrot_ex, 'payload');
say $ex.WHAT;
alive
Exception
Base()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment