diff options
author | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-05-01 08:56:45 +0000 |
---|---|---|
committer | matz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 1998-05-01 08:56:45 +0000 |
commit | 53118356b53259b456aabc11fb1212d965251fc4 (patch) | |
tree | cfa16b2fa793fb9a4691f21bd028a0170a598cff /error.c | |
parent | 896c0dff6330d461ce428d61df0f60fb8bad07a7 (diff) |
exception model changed
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/v1_1r@201 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'error.c')
-rw-r--r-- | error.c | 63 |
1 files changed, 34 insertions, 29 deletions
@@ -212,9 +212,10 @@ rb_check_type(x, t) #include "errno.h" extern VALUE cString; -VALUE eThrowable, eExceptional; -VALUE eGlobalExit, eException; +VALUE eException; VALUE eSystemExit, eInterrupt, eFatal; +VALUE eDefaultRescue; +VALUE eStandardError; VALUE eRuntimeError; VALUE eSyntaxError; VALUE eTypeError; @@ -328,6 +329,7 @@ exception(argc, argv) VALUE *argv; { void ArgError(); + VALUE etype = eStandardError; VALUE v = Qnil; int i; ID id; @@ -335,6 +337,10 @@ exception(argc, argv) if (argc == 0) { ArgError("wrong # of arguments"); } + if (TYPE(argv[argc-1]) == T_CLASS) { + etype = argv[argc-1]; + argc--; argv++; + } for (i=0; i<argc; i++) { /* argument check */ id = rb_to_id(argv[i]); if (!rb_id2name(id)) { @@ -345,7 +351,9 @@ exception(argc, argv) } } for (i=0; i<argc; i++) { - v = rb_define_class_under(the_class, rb_id2name(rb_to_id(argv[i])), eException); + v = rb_define_class_under(the_class, + rb_id2name(rb_to_id(argv[i])), + etype); } return v; } @@ -372,31 +380,28 @@ static void init_syserr(); void Init_Exception() { - eThrowable = rb_define_module("Throwable"); - eGlobalExit = rb_define_class("GlobalExit", cString); - rb_include_module(eGlobalExit, eThrowable); - rb_define_singleton_method(eGlobalExit, "new", exc_s_new, -1); - rb_define_method(eGlobalExit, "new", exc_new_method, 1); - rb_define_method(eGlobalExit, "inspect", exc_inspect, 0); - - eSystemExit = rb_define_class("SystemExit", eGlobalExit); - eFatal = rb_define_class("fatal", eGlobalExit); - eInterrupt = rb_define_class("Interrupt", eGlobalExit); - - eExceptional = rb_define_module("Exceptional"); - rb_include_module(eExceptional, eThrowable); - eException = rb_define_class("Exception", eGlobalExit); - rb_include_module(eException, eExceptional); - eSyntaxError = rb_define_class("SyntaxError", eException); - eTypeError = rb_define_class("TypeError", eException); - eArgError = rb_define_class("ArgumentError", eException); - eNameError = rb_define_class("NameError", eException); - eIndexError = rb_define_class("IndexError", eException); - eNotImpError = rb_define_class("NotImplementError", eException); - eLoadError = rb_define_class("LoadError", eException); - - eRuntimeError = rb_define_class("RuntimeError", eException); - eSecurityError = rb_define_class("SecurityError", eException); + eException = rb_define_class("Exception", cString); + rb_define_singleton_method(eException, "new", exc_s_new, -1); + rb_define_method(eException, "new", exc_new_method, 1); + rb_define_method(eException, "inspect", exc_inspect, 0); + + eSystemExit = rb_define_class("SystemExit", eException); + eFatal = rb_define_class("fatal", eException); + eInterrupt = rb_define_class("Interrupt", eException); + + eDefaultRescue = rb_define_module("DefaultRescue"); + eStandardError = rb_define_class("StandardError", eException); + rb_include_module(eStandardError, eDefaultRescue); + eSyntaxError = rb_define_class("SyntaxError", eStandardError); + eTypeError = rb_define_class("TypeError", eStandardError); + eArgError = rb_define_class("ArgumentError", eStandardError); + eNameError = rb_define_class("NameError", eStandardError); + eIndexError = rb_define_class("IndexError", eStandardError); + eNotImpError = rb_define_class("NotImplementError", eStandardError); + eLoadError = rb_define_class("LoadError", eStandardError); + + eRuntimeError = rb_define_class("RuntimeError", eStandardError); + eSecurityError = rb_define_class("SecurityError", eStandardError); init_syserr(); @@ -524,7 +529,7 @@ rb_sys_fail(mesg) static void init_syserr() { - eSystemCallError = rb_define_class("SystemCallError", eException); + eSystemCallError = rb_define_class("SystemCallError", eStandardError); mErrno = rb_define_module("Errno"); syserr_list = ALLOC_N(VALUE, sys_nerr+1); MEMZERO(syserr_list, VALUE, sys_nerr+1); |