C function rb_raise doesn't behave the same as Ruby keyword 'raise'

Discussion in 'Ruby' started by Asfand Yar Qazi, Jan 19, 2006.

  1. Hi,

    Where in Ruby, you can do a:

    e = StandardError.new("Bog")
    raise(e)

    in C, you can't do the equivalent:

    VALUE exobj = rb_funcall(eMyEx, rb_intern("new"), 0);
    rb_raise(exobj, "Bog");

    Why?

    If I wanted to do this, how could I?

    --
    Entry in RollerCoaster Tycoon 2 readme.txt file:
    RollerCoaster Tycoon2 must be played on a video card capable of 640x480 screen
    resolution at a bit depth setting of 256 bits.
    And the proof that playing too many strategy games causes loss of humour:
    http://tinyurl.com/dyrtt
     
    Asfand Yar Qazi, Jan 19, 2006
    #1
    1. Advertisements

  2. Asfand Yar Qazi

    Guest

    rb_funcall lets you pass arguments to the method. In this case, pass
    the Ruby String version of "Bog".

    VALUE bog = rb_str_new2("Bog");
    VALUE exobj = rb_funcall(eMyEx, rb_intern("new"), 1, bog);

    rb_raise(exobj, "");
     
    , Jan 19, 2006
    #2
    1. Advertisements

  3. wrote:
    > rb_funcall lets you pass arguments to the method. In this case, pass
    > the Ruby String version of "Bog".
    >
    > VALUE bog = rb_str_new2("Bog");
    > VALUE exobj = rb_funcall(eMyEx, rb_intern("new"), 1, bog);
    >
    > rb_raise(exobj, "");
    >


    Argh, perhaps I didn't explain this too well.

    You don't understand - the line 'rb_raise(exobj, "");' would not do what was
    expected. It would (under ruby 1.8.2 last time I checked) crash the interpreter
    or (under 1.8.4) issue a NoMethodError exception saying 'undefined method `new'
    for #<Mod::MyEx: Mod::MyEx>' or something similar. I.e. rb_raise tries to call
    'new' on its first argument, and if that's a non-Class object, then....

    Which gives me an idea on how to kludge together something that works..... a
    'new' instance method that returns an identical copy of the object it is called
    on.... hmm....... *loses himself in deep thought*
     
    Asfand Yar Qazi, Jan 19, 2006
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jacol

    raise or not to raise [Newbie]

    Jacol, Feb 3, 2007, in forum: Python
    Replies:
    5
    Views:
    645
    Gabriel Genellina
    Feb 5, 2007
  2. ernest
    Replies:
    2
    Views:
    440
    Roy Smith
    Nov 14, 2010
  3. Jack Bates
    Replies:
    0
    Views:
    442
    Jack Bates
    May 2, 2011
  4. Alexey Verkhovsky
    Replies:
    8
    Views:
    258
    Hal Fulton
    Jul 18, 2004
  5. Just Another Victim of the Ambient Morality

    How can two references to the same object behave differently?

    Just Another Victim of the Ambient Morality, Apr 20, 2006, in forum: Ruby
    Replies:
    5
    Views:
    267
    Robert Klemme
    Apr 20, 2006
  6. Iñaki Baz Castillo
    Replies:
    2
    Views:
    195
    Iñaki Baz Castillo
    Feb 7, 2011
  7. bvdp

    Raise X or Raise X()?

    bvdp, Mar 11, 2012, in forum: Python
    Replies:
    10
    Views:
    639
    Stefan Behnel
    Mar 12, 2012
  8. usgog
    Replies:
    2
    Views:
    266
Loading...