Hello,
I create the following code to create a custom exception
using *three* parameter to initialize.
Q: is this code ok?
Thanks for help...
···
============================================================
#include "msgque_ruby.h"
static VALUE cMqSException;
static ID id_new;
static ID id_num;
static ID id_code;
static ID id_txt;
void NS(MqSException_Raise) (struct MqS* mqctx) {
MQ_INT num = MqErrorGetNumI (mqctx);
MQ_INT code = MqErrorGetCodeI (mqctx);
MQ_CST text = MqErrorGetText (mqctx);
VALUE exc = rb_funcall(cMqSException, id_new,
3, INT2NUM(num), INT2NUM(code), rb_str_new2(text)
);
rb_exc_raise(exc);
}
static VALUE initialize(VALUE self, VALUE num, VALUE code, VALUE txt)
{
rb_ivar_set(self, id_num, num);
rb_ivar_set(self, id_code, code);
rb_ivar_set(self, id_txt, txt);
return self;
}
void NS(MqSException_Init) (void) {
cMqSException = rb_define_class("MqSException", rb_eException);
rb_define_method(cMqSException, "initialize", initialize, 3);
rb_define_attr(cMqSException, "num", 1, 0);
rb_define_attr(cMqSException, "code", 0, 0);
rb_define_attr(cMqSException, "txt", 1, 0);
id_new = rb_intern("new");
id_num = rb_intern("@num");
id_code = rb_intern("@code");
id_txt = rb_intern("@txt");
}
mfg, Andreas Otto