B
Bennett, Patrick
I'm having problems with my Ruby module.
The instance variables I'm setting in a custom exception class don't
appear to be getting set.
What am I doing wrong?
Declaration code:
EventExceptionKlass = rb_define_class("EventException",
rb_eStandardError);
rb_define_method(EventExceptionKlass, "event",
VALUEFUNC(EventExcepGetEvent), 0); // just calls return
rb_iv_get(self,"@event")
rb_define_method(EventExceptionKlass, "msg",
VALUEFUNC(EventExcepGetMessage), 0); // just calls return
rb_iv_get(self,"@msg")
Code where exception is raised.
catch (const RecoCommonLib::EventException& ex)
{
VALUE throwex = rb_exc_new2( EventExceptionKlass, ex.what());
rb_iv_set(throwex, "@event", rb_str_new2( [pointer to some
string]) );
rb_iv_set(throwex, "@msg", rb_str_new2( [pointer to another
string])) );
rb_exc_raise(throwex);
}
When I catch the Ruby "EventException" class in a rescue class (which
happens correctly) then 'event' and 'msg' are always nil (if I test
them).
...
rescue EventException => ex
puts "Event:#{ex.event} Msg:#{ex.msg} Exception:#{ex}"
end
The instance variables I'm setting in a custom exception class don't
appear to be getting set.
What am I doing wrong?
Declaration code:
EventExceptionKlass = rb_define_class("EventException",
rb_eStandardError);
rb_define_method(EventExceptionKlass, "event",
VALUEFUNC(EventExcepGetEvent), 0); // just calls return
rb_iv_get(self,"@event")
rb_define_method(EventExceptionKlass, "msg",
VALUEFUNC(EventExcepGetMessage), 0); // just calls return
rb_iv_get(self,"@msg")
Code where exception is raised.
catch (const RecoCommonLib::EventException& ex)
{
VALUE throwex = rb_exc_new2( EventExceptionKlass, ex.what());
rb_iv_set(throwex, "@event", rb_str_new2( [pointer to some
string]) );
rb_iv_set(throwex, "@msg", rb_str_new2( [pointer to another
string])) );
rb_exc_raise(throwex);
}
When I catch the Ruby "EventException" class in a rescue class (which
happens correctly) then 'event' and 'msg' are always nil (if I test
them).
...
rescue EventException => ex
puts "Event:#{ex.event} Msg:#{ex.msg} Exception:#{ex}"
end