summaryrefslogtreecommitdiffhomepage
path: root/src/error.c
diff options
context:
space:
mode:
authorTomoyuki Sahara <[email protected]>2013-03-13 09:55:06 +0900
committerTomoyuki Sahara <[email protected]>2013-03-13 09:55:06 +0900
commit7103e032746df1b4359f6e6a6bb117ad7a434aa1 (patch)
tree9fd0b2add554136e00e464374e4c2cfc4612204b /src/error.c
parent46d8c51763bd13b69a4234f0d4be05cbfd8ae401 (diff)
downloadmruby-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.c16
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