diff options
Diffstat (limited to 'src/error.c')
| -rw-r--r-- | src/error.c | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/error.c b/src/error.c index ed30173bc..6bd891768 100644 --- a/src/error.c +++ b/src/error.c @@ -5,6 +5,7 @@ */ #include "mruby.h" +#include <errno.h> #include <stdarg.h> #include <setjmp.h> #include <string.h> @@ -89,7 +90,7 @@ exc_to_s(mrb_state *mrb, mrb_value exc) { mrb_value mesg = mrb_attr_get(mrb, exc, mrb_intern(mrb, "mesg")); - if (mrb_nil_p(mesg)) return mrb_str_new2(mrb, mrb_obj_classname(mrb, exc)); + if (mrb_nil_p(mesg)) return mrb_str_new_cstr(mrb, mrb_obj_classname(mrb, exc)); return mesg; } @@ -140,7 +141,7 @@ exc_inspect(mrb_state *mrb, mrb_value exc) } } else { - str = mrb_str_new2(mrb, mrb_obj_classname(mrb, exc)); + str = mrb_str_new_cstr(mrb, mrb_obj_classname(mrb, exc)); if (!mrb_nil_p(mesg) && RSTRING_LEN(mesg) > 0) { mrb_str_cat2(mrb, str, ": "); mrb_str_append(mrb, str, mesg); @@ -218,7 +219,7 @@ void mrb_raise(mrb_state *mrb, struct RClass *c, const char *msg) { mrb_value mesg; - mesg = mrb_str_new2(mrb, msg); + mesg = mrb_str_new_cstr(mrb, msg); mrb_exc_raise(mrb, mrb_exc_new3(mrb, c, mesg)); } @@ -401,7 +402,20 @@ mrb_make_exception(mrb_state *mrb, int argc, mrb_value *argv) void mrb_sys_fail(mrb_state *mrb, const char *mesg) { - mrb_raise(mrb, E_RUNTIME_ERROR, mesg); + struct RClass *sce; + mrb_int no; + + no = (mrb_int)errno; + if (mrb_class_defined(mrb, "SystemCallError")) { + sce = mrb_class_get(mrb, "SystemCallError"); + if (mesg != NULL) { + mrb_funcall(mrb, mrb_obj_value(sce), "_sys_fail", 2, mrb_fixnum_value(no), mrb_str_new_cstr(mrb, mesg)); + } else { + mrb_funcall(mrb, mrb_obj_value(sce), "_sys_fail", 1, mrb_fixnum_value(no)); + } + } else { + mrb_raise(mrb, E_RUNTIME_ERROR, mesg); + } } void |
