ext/rjbexception.c in rjb-1.2.5 vs ext/rjbexception.c in rjb-1.2.6

- old
+ new

@@ -10,11 +10,11 @@ * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * - * $Id: rjbexception.c 119 2010-06-04 12:51:34Z arton $ + * $Id: rjbexception.c 126 2010-07-22 13:58:15Z arton $ */ #include "ruby.h" #include "extconf.h" #if RJB_RUBY_VERSION_CODE < 190 @@ -24,10 +24,16 @@ #endif #include "jniwrap.h" #include "riconv.h" #include "rjb.h" +static VALUE missing_delegate(int argc, VALUE* argv, VALUE self) +{ + ID rmid = rb_to_id(argv[0]); + return rb_funcall(rb_ivar_get(self, rb_intern("@cause")), rmid, argc - 1, argv + 1); +} + /* * handle Java exception * At this time, the Java exception is defined without the package name. * This design may change in future release. */ @@ -52,10 +58,11 @@ cname = rb_str_new2(pcls); rexp = rb_hash_aref(rjb_loaded_classes, cname); if (rexp == Qnil) { rexp = rb_define_class(pcls, rb_eStandardError); + rb_define_method(rexp, "method_missing", missing_delegate, -1); #if defined(HAVE_RB_HASH_ASET) || defined(RUBINIUS) rb_hash_aset(rjb_loaded_classes, cname, rexp); #else #ifdef RHASH_TBL st_insert(RHASH_TBL(rjb_loaded_classes), cname, rexp); @@ -135,14 +142,19 @@ { rexp = rjb_get_exception_class(jenv, str); } if (rexp == Qnil) { + (*jenv)->DeleteLocalRef(jenv, exp); rb_raise(rb_eRuntimeError, "%s", msg); } else { - rb_raise(rexp, "%s", msg); + VALUE rexpi = rb_funcall(rexp, rb_intern("new"), 1, rb_str_new2(msg)); + jvalue val; + val.l = exp; + rb_ivar_set(rexpi, rb_intern("@cause"), jv2rv(jenv, val)); + rb_exc_raise(rexpi); } } } }