Last active
August 29, 2015 14:14
-
-
Save skids/5cbec5d3c24512d44a3a to your computer and use it in GitHub Desktop.
Typed exceptions to use with NativeCall
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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