From: ts Date: 2003-11-14T01:40:55+09:00 Subject: Re: Problem with exception class and instance vars >>>>> "B" == Bennett, Patrick writes: B> What am I doing wrong? Difficult to say : probably ruby don't like C++ :-)) svg% cat aa.c #include static VALUE evx; static VALUE aa_tt(obj) VALUE obj; { VALUE thr = rb_exc_new2(evx, ""); rb_iv_set(thr, "@event", rb_str_new2("")); rb_iv_set(thr, "@msg", rb_str_new2("")); rb_exc_raise(thr); } static VALUE aa_event(obj) VALUE obj; { return rb_iv_get(obj, "@event"); } static VALUE aa_msg(obj) VALUE obj; { return rb_iv_get(obj, "@msg"); } void Init_aa() { evx = rb_define_class("EventException", rb_eStandardError); rb_define_method(evx, "event", aa_event, 0); rb_define_method(evx, "msg", aa_msg, 0); rb_define_global_function("tt", aa_tt, 0); } svg% svg% cat b.rb #!/usr/bin/ruby require 'aa' begin tt rescue EventException => ex puts "Event : #{ex.event} Msg : #{ex.msg} Exception : #{ex}" end svg% svg% b.rb Event : Msg : Exception : svg% Guy Decoux