Skip to content

Instantly share code, notes, and snippets.

@dominiek
Created January 7, 2010 03:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save dominiek/270959 to your computer and use it in GitHub Desktop.
Save dominiek/270959 to your computer and use it in GitHub Desktop.
/* Basically, I want to throw a custom exception from C++. I'm kind of lost on how to do that :/ */
// exceptions.hpp
class V8UnknownReturnValueException : public Rice::Exception {
};
Rice::Object rb_eUnknownReturnValueException;
// Initializing the guy (rb_mV8 is a defined module)
rb_eUnknownReturnValueException = rb_mV8.define_class<V8UnknownReturnValueException>("UnknownReturnValueException");
// Throwing the exception:
throw Rice::Exception(rb_eUnknownReturnValueException, "Fly little bird!");
/* When running it:
ruby examples/hello.rb
examples/hello.rb:13:in `new': allocator undefined for V8::UnknownReturnValueException (TypeError)
from examples/hello.rb:13:in `run'
from examples/hello.rb:13
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment