Commit 97e94247 authored by Yukihiro Matsumoto's avatar Yukihiro Matsumoto

Kernel#raise: better argument check

parent 8f9b958f
...@@ -1085,7 +1085,7 @@ mrb_obj_public_methods(mrb_state *mrb, mrb_value self) ...@@ -1085,7 +1085,7 @@ mrb_obj_public_methods(mrb_state *mrb, mrb_value self)
* call-seq: * call-seq:
* raise * raise
* raise(string) * raise(string)
* raise(exception [, string [, array]]) * raise(exception [, string])
* *
* With no arguments, raises a <code>RuntimeError</code> * With no arguments, raises a <code>RuntimeError</code>
* With a single +String+ argument, raises a * With a single +String+ argument, raises a
...@@ -1103,14 +1103,24 @@ mrb_obj_public_methods(mrb_state *mrb, mrb_value self) ...@@ -1103,14 +1103,24 @@ mrb_obj_public_methods(mrb_state *mrb, mrb_value self)
mrb_value mrb_value
mrb_f_raise(mrb_state *mrb, mrb_value self) mrb_f_raise(mrb_state *mrb, mrb_value self)
{ {
mrb_value *argv; mrb_value a[2];
int argc; int argc;
mrb_get_args(mrb, "*", &argv, &argc); argc = mrb_get_args(mrb, "|oo", &a[0], &a[1]);
if (argc == 0) { switch (argc) {
case 0:
mrb_raise(mrb, mrb->eRuntimeError_class, ""); mrb_raise(mrb, mrb->eRuntimeError_class, "");
break;
case 1:
a[1] = mrb_check_string_type(mrb, a[0]);
if (!mrb_nil_p(a[1])) {
argc = 2;
a[0] = mrb_obj_value(mrb->eRuntimeError_class);
}
/* fall through */
default:
mrb_exc_raise(mrb, mrb_make_exception(mrb, argc, a));
} }
mrb_exc_raise(mrb, mrb_make_exception(mrb, argc, argv));
return mrb_nil_value(); /* not reached */ return mrb_nil_value(); /* not reached */
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment