Skip to content

Instantly share code, notes, and snippets.

@clowder
Created March 18, 2012 23:23
Show Gist options
  • Save clowder/2084885 to your computer and use it in GitHub Desktop.
Save clowder/2084885 to your computer and use it in GitHub Desktop.
How to rescue your Rubies in C!
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);
}
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