Skip to content

Instantly share code, notes, and snippets.

@skids
Last active August 29, 2015 14:14
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 skids/5cbec5d3c24512d44a3a to your computer and use it in GitHub Desktop.
Save skids/5cbec5d3c24512d44a3a to your computer and use it in GitHub Desktop.
Typed exceptions to use with NativeCall
# Add them if you've got them.
our class X::NativeCall::DeadObject is Exception {
has $.status = "no longer valid for use";
has $.type = "UNSPECIFIED";
has $.lib = "any library";
method message {
"This object of type $.type is $.status with $.lib."
}
}
our class X::NativeCall::CannotClone is Exception {
has $.type = "UNSPECIFIED";
method message {
"Native object of type $.type cannot be cloned."
}
}
our class X::NativeCall::OverflowProhibited is Exception {
has $.dtype;
has $.value;
method message {
my $dtype = " of " ~ $!dtype if $!dtype.chars;
my $value = " by value" ~ $!value if $!value.chars;
"Prohibited overflow$dtype$value because that is dangerous here.";
}
}
our class X::NativeCall::NativeError is Exception {
has $.errno = "";
has $.error = "";
has $.func = "";
has $.lib = "";
method message {
my $m = "Unexpected error from native API call";
$m ~= " ($.errno)" if $.errno.chars;
$m ~= ": $.error" if $.error.chars;
if $.func.chars or $.lib.chars {
$m ~= " (in ";
$m ~= " function $.func" if $.func.chars;
$m ~= " library $.lib" if $.lib.chars;
$m ~= ")";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment