mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
error.c: store error message converted as a string.
This is controversial since this change alters the `raise` behavior. Previously, when an object that cannot be converted to a string, it just ignore message when it's printed (using `Exception#inspect`). But after this change, `raise` (more precisly `Exception.new`) raises TypeError exception. I think the new behavior is clearer, more intuitive.
This commit is contained in:
+6
-14
@@ -21,26 +21,18 @@
|
||||
void
|
||||
mrb_exc_mesg_set(mrb_state *mrb, struct RException *exc, mrb_value mesg)
|
||||
{
|
||||
if (!mrb_immediate_p(mesg)) {
|
||||
exc->mesg = mrb_obj_ptr(mesg);
|
||||
mrb_field_write_barrier_value(mrb, (struct RBasic*)exc, mesg);
|
||||
mrb_iv_remove(mrb, mrb_obj_value(exc), MRB_SYM(mesg));
|
||||
}
|
||||
else {
|
||||
exc->mesg = NULL;
|
||||
mrb_obj_iv_set(mrb, (struct RObject*)exc, MRB_SYM(mesg), mesg);
|
||||
if (!mrb_string_p(mesg)) {
|
||||
mesg = mrb_obj_as_string(mrb, mesg);
|
||||
}
|
||||
exc->mesg = mrb_obj_ptr(mesg);
|
||||
mrb_field_write_barrier_value(mrb, (struct RBasic*)exc, mesg);
|
||||
}
|
||||
|
||||
mrb_value
|
||||
mrb_exc_mesg_get(mrb_state *mrb, struct RException *exc)
|
||||
{
|
||||
if (exc->mesg) {
|
||||
return mrb_obj_value(exc->mesg);
|
||||
}
|
||||
else {
|
||||
return mrb_obj_iv_get(mrb, (struct RObject*)exc, MRB_SYM(mesg));
|
||||
}
|
||||
if (exc->mesg == NULL) return mrb_nil_value();
|
||||
return mrb_obj_value(exc->mesg);
|
||||
}
|
||||
|
||||
MRB_API mrb_value
|
||||
|
||||
Reference in New Issue
Block a user