Domanda

Nel rubino,

begin
  # ...
rescue
  # ...
end

non rileverà le eccezioni che non sono sottoclassi di StandardError.In C,

rb_rescue(x, Qnil, y, Qnil);

VALUE x(void) { /* ... */ return Qnil; }
VALUE y(void) { /* ... */ return Qnil; }

farà la stessa cosa.Come posso rescue Exception => e da un'estensione Ruby C (invece di just rescue => e)?

È stato utile?

Soluzione

Ruby ha bisogno di più documentazione.Ho dovuto entrare nel codice sorgente di Ruby e questo è quello che ho trovato:

VALUE
rb_rescue(VALUE (* b_proc)(ANYARGS), VALUE data1,
      VALUE (* r_proc)(ANYARGS), VALUE data2)
{
    return rb_rescue2(b_proc, data1, r_proc, data2, rb_eStandardError,
              (VALUE)0);
}

Quindi, la risposta alla mia domanda (immagino) sarebbe:

rb_rescue2(x, Qnil, y, Qnil, rb_eException, (VALUE)0);

VALUE x(void) { /* ... */ return Qnil; }
VALUE y(void) { /* ... */ return Qnil; }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top