Ruby-C-Erweiterungen:Wie kann ich alle Ausnahmen abfangen, einschließlich Dinge, die keine StandardErrors sind?
-
13-09-2020 - |
Frage
In Rubin,
begin
# ...
rescue
# ...
end
fängt keine Ausnahmen ab, die keine Unterklassen von sind StandardError
.In C,
rb_rescue(x, Qnil, y, Qnil);
VALUE x(void) { /* ... */ return Qnil; }
VALUE y(void) { /* ... */ return Qnil; }
werde das Gleiche tun.Wie kann ich rescue Exception => e
von einer Ruby-C-Erweiterung (statt nur rescue => e
)?
Lösung
Ruby benötigt mehr Dokumentation.Ich musste in den Ruby-Quellcode gehen und das habe ich gefunden:
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);
}
Die Antwort auf meine Frage wäre also (schätze ich):
rb_rescue2(x, Qnil, y, Qnil, rb_eException, (VALUE)0);
VALUE x(void) { /* ... */ return Qnil; }
VALUE y(void) { /* ... */ return Qnil; }
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow