make_exception: do not goto into a branch
I'm not necessarily against every goto in general, but jumping into a branch is definitely a bad idea. Better refactor.
This commit is contained in:
parent
13bdbfcecb
commit
4606ec4925
Notes:
git
2020-06-29 11:07:06 +09:00
33
eval.c
33
eval.c
@ -806,44 +806,37 @@ static VALUE
|
|||||||
make_exception(int argc, const VALUE *argv, int isstr)
|
make_exception(int argc, const VALUE *argv, int isstr)
|
||||||
{
|
{
|
||||||
VALUE mesg, exc;
|
VALUE mesg, exc;
|
||||||
int n;
|
|
||||||
|
|
||||||
mesg = Qnil;
|
mesg = Qnil;
|
||||||
switch (argc) {
|
switch (argc) {
|
||||||
case 0:
|
case 0:
|
||||||
break;
|
return Qnil;
|
||||||
case 1:
|
case 1:
|
||||||
exc = argv[0];
|
exc = argv[0];
|
||||||
if (NIL_P(exc))
|
if (isstr &&! NIL_P(exc)) {
|
||||||
break;
|
|
||||||
if (isstr) {
|
|
||||||
mesg = rb_check_string_type(exc);
|
mesg = rb_check_string_type(exc);
|
||||||
if (!NIL_P(mesg)) {
|
if (!NIL_P(mesg)) {
|
||||||
mesg = rb_exc_new3(rb_eRuntimeError, mesg);
|
mesg = rb_exc_new3(rb_eRuntimeError, mesg);
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
n = 0;
|
|
||||||
goto exception_call;
|
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
case 3:
|
case 3:
|
||||||
exc = argv[0];
|
|
||||||
n = 1;
|
|
||||||
exception_call:
|
|
||||||
mesg = rb_check_funcall(exc, idException, n, argv+1);
|
|
||||||
if (mesg == Qundef) {
|
|
||||||
rb_raise(rb_eTypeError, "exception class/object expected");
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
rb_error_arity(argc, 0, 3);
|
rb_error_arity(argc, 0, 3);
|
||||||
}
|
}
|
||||||
if (argc > 0) {
|
if (NIL_P(mesg)) {
|
||||||
if (!rb_obj_is_kind_of(mesg, rb_eException))
|
mesg = rb_check_funcall(argv[0], idException, argc != 1, &argv[1]);
|
||||||
rb_raise(rb_eTypeError, "exception object expected");
|
}
|
||||||
if (argc > 2)
|
if (mesg == Qundef) {
|
||||||
set_backtrace(mesg, argv[2]);
|
rb_raise(rb_eTypeError, "exception class/object expected");
|
||||||
|
}
|
||||||
|
if (!rb_obj_is_kind_of(mesg, rb_eException)) {
|
||||||
|
rb_raise(rb_eTypeError, "exception object expected");
|
||||||
|
}
|
||||||
|
if (argc == 3) {
|
||||||
|
set_backtrace(mesg, argv[2]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return mesg;
|
return mesg;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user