Howto ruby custom exception using the C-API

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

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 O.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.15 (GNU/Linux)
Comment: Using GnuPG with SUSE - http://enigmail.mozdev.org/

iQEcBAEBAgAGBQJMqb9+AAoJEGTcPijNG3/A0T8H/0v0lMeQanc1ebgR+89bqfN9
h1d7JuznukJgmfwkmoMcMfjQTLJZl/fxJ0frq/NyZ8pHk1VYStAO/wJtAmT9cfWJ
Pqrk8Ko4LS/aKTmfPt1WBf0zUYXrUFBZ41PbWSXlvsKCnnYFQtHSAKgnSODa238W
H46zCTSOl3hV5iST+zigtAvXTrjNYJQoesRCc3+GBTrnNNzsyoClY4STM7vuyMrN
wV6qHnex+NsvomF//ANw5Nk8Oeh5JyOGkOfLTCecz6I/SCWxvGR1VrLmMuyAMXQg
Xw9puxCuYu3avIHTXJfd5lNi6o8CPlDKowgZfqA7LV6SgU3pQmGZ41nGPZnhdOs=
=K1Hl
-----END PGP SIGNATURE-----