From: An Onymous Date: 2007-10-20T12:40:19+09:00 Subject: Re: extendig ruby: defining classes and creating objects fro Thank you. Now it works. I ended up writing an updated version of rb_raise which behaves more like the ruby "raise" global function. That is: myrb_raise(Qnil,NULL) behaves like "raise" myrb_raise(Qnil,fmt,...) behaves like "raise " raising a RuntimeError with the given message myrb_raise(exc,NULL) behaves like "raise " where exc can be either a class OR AN EXCEPTION OBJECT (if exc is an exception object, its message is preserved) and myrb_raise(exc,fmt,...) behaves like "raise ," that is like the previous one but also setting the exception message. Here it is: VALUE myrb_raise(VALUE exc, const char *fmt, ...) { if(!NIL_P(exc)) { ID exception = rb_intern("exception"); if(!rb_respond_to(exc, exception)) rb_raise(rb_eTypeError, "exception class/object expected"); } if(fmt) { va_list args; char buf[BUFSIZ]; VALUE msg; va_init_list(args,fmt); vsnprintf(buf, BUFSIZ, fmt, args); va_end(args); msg=rb_str_new2(buf); if(NIL_P(exc)) exc = rb_class_new_instance(1, &msg, rb_eRuntimeError); else exc = rb_funcall(exc, exception, 1, msg); } rb_exc_raise(exc); } -- Posted via http://www.ruby-forum.com/.