Created
March 18, 2012 23:23
-
-
Save clowder/2084885 to your computer and use it in GitHub Desktop.
How to rescue your Rubies in C!
This file contains hidden or 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
static void i_fail(VALUE self) | |
{ | |
rb_raise(rb_eRuntimeError, "Oh knowz!"); | |
} | |
static void rescue(VALUE self, VALUE exception) | |
{ | |
/* This function _is not_ in <ruby.h> | |
* http://clalance.blogspot.co.uk/2011/01/writing-ruby-extensions-in-c-part-5.html | |
*/ | |
rb_exc_raise(exception); | |
} | |
static void demo(VALUE self) | |
{ | |
rb_rescue(i_fail, self, rescue, self); | |
} |
This file contains hidden or 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
def demo | |
begin | |
i_fail | |
rescue Exception => ex | |
throw ex | |
end | |
end | |
def i_fail | |
fail "Oh knowz!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment