From: matz@... (Yukihiro Matsumoto) Date: 2001-07-16T00:08:20+09:00 Subject: [ruby-talk:17882] Re: Trapping Ruby exceptions from C Hi, In message "[ruby-talk:17864] Trapping Ruby exceptions from C" on 01/07/15, Tobin Baker writes: |// use rb_rescue to catch exception | VALUE packed_args = rb_ary_new3(3, servant->impl, ID2SYM(rb_intern(name)), args); | VALUE error_holder = rb_class_new_instance(0, 0, rorbit_c_CORBA_ORBit_ErrorHolder); | results = rb_rescue(rorbit_apply_try, packed_args, rorbit_trap_exception, error_holder); | error = rb_iv_get(error_holder, "@error"); | |Is there a way to retrieve an exception from the method called by |rb_apply without having to use a helper class? Use pointer to the variable, i.e. static VALUE rorbit_trap_exception(VALUE* error_holder, VALUE error) { if (!RTEST(rb_obj_is_kind_of(error, rb_eStandardError))) *error_holder = rb_exc_new2(rb_eTypeError, "not an exception"); else *error_holder = error; return Qnil; } ... VALUE packed_args = rb_ary_new3(3, servant->impl, ID2SYM(rb_intern(name)), args); results = rb_rescue(rorbit_apply_try, packed_args, rorbit_trap_exception, (VALUE)&error); Hope this helps. matz.