diff options
| author | Tomoyuki Sahara <[email protected]> | 2013-03-13 09:55:06 +0900 |
|---|---|---|
| committer | Tomoyuki Sahara <[email protected]> | 2013-03-13 09:55:06 +0900 |
| commit | 7103e032746df1b4359f6e6a6bb117ad7a434aa1 (patch) | |
| tree | 9fd0b2add554136e00e464374e4c2cfc4612204b /src/error.c | |
| parent | 46d8c51763bd13b69a4234f0d4be05cbfd8ae401 (diff) | |
| download | mruby-7103e032746df1b4359f6e6a6bb117ad7a434aa1.tar.gz mruby-7103e032746df1b4359f6e6a6bb117ad7a434aa1.zip | |
mrb_sys_fail raises SystemCallError if we have it.
Diffstat (limited to 'src/error.c')
| -rw-r--r-- | src/error.c | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/src/error.c b/src/error.c index ed30173bc..9dd8890ba 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> @@ -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_new2(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 |
