首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

SystemExit

Parent:Exception

通过exit启动终止脚本。

公共类方法

new → system_exit Show source

new(status) → system_exit

new(status, msg) → system_exit

new(msg) → system_exit

SystemExit用给定的状态和消息创建一个新的异常。状态为true,false或整数。如果没有给出状态,则使用true。

代码语言:javascript
复制
static VALUE
exit_initialize(int argc, VALUE *argv, VALUE exc)
{
    VALUE status;
    if (argc > 0) {
        status = *argv;

        switch (status) {
          case Qtrue:
            status = INT2FIX(EXIT_SUCCESS);
            ++argv;
            --argc;
            break;
          case Qfalse:
            status = INT2FIX(EXIT_FAILURE);
            ++argv;
            --argc;
            break;
          default:
            status = rb_check_to_int(status);
            if (NIL_P(status)) {
                status = INT2FIX(EXIT_SUCCESS);
            }
            else {
#if EXIT_SUCCESS != 0
                if (status == INT2FIX(0))
                    status = INT2FIX(EXIT_SUCCESS);
#endif
                ++argv;
                --argc;
            }
            break;
        }
    }
    else {
        status = INT2FIX(EXIT_SUCCESS);
    }
    rb_call_super(argc, argv);
    rb_ivar_set(exc, id_status, status);
    return exc;
}

公共实例方法

status → integer Show source

返回与此系统出口关联的状态值。

代码语言:javascript
复制
static VALUE
exit_status(VALUE exc)
{
    return rb_attr_get(exc, id_status);
}

success? → true or false Show source

如果退出成功则返回true,否则返回false。

代码语言:javascript
复制
static VALUE
exit_success_p(VALUE exc)
{
    VALUE status_val = rb_attr_get(exc, id_status);
    int status;

    if (NIL_P(status_val))
        return Qtrue;
    status = NUM2INT(status_val);
    if (WIFEXITED(status) && WEXITSTATUS(status) == EXIT_SUCCESS)
        return Qtrue;

    return Qfalse;
}

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com