System的exit

System的exit

源码

 /**
     * Terminates the currently running Java Virtual Machine. The
     * argument serves as a status code; by convention, a nonzero status
     * code indicates abnormal termination.
     * <p>
     * This method calls the <code>exit</code> method in class
     * <code>Runtime</code>. This method never returns normally.
     * <p>
     * The call <code>System.exit(n)</code> is effectively equivalent to
     * the call:
     * <blockquote><pre>
     * Runtime.getRuntime().exit(n)
     * </pre></blockquote>
     *
     * @param      status   exit status.
     * @throws  SecurityException
     *        if a security manager exists and its <code>checkExit</code>
     *        method doesn't allow exit with the specified status.
     * @see        java.lang.Runtime#exit(int)
     */
    public static void exit(int status) {
        Runtime.getRuntime().exit(status);
    }

功 能: 关闭所有文件,终止正在执行的进程。

exit(0):正常运行程序并退出程序;

exit(1):非正常运行导致退出程序;

测试方法:

 // 测试方法
    public static void main(String[] args) {

        StackType stackType = new StackType();
        try {
            DATA3 data3 = stackType.PopST(stackType); // 此处调用了 exit 直接关闭了当前现成 之后方法都未执行
        }catch (Exception ee){
            System.out.printf("sss");
        }


    }


    DATA3 PopST(StackType s){
        if(s.top==0){
            System.out.printf("栈为空!");
            System.exit(0);
            System.out.printf("关闭后"); //永远不会执行
        }
        return (s.data[s.top--]);
    }

控制台输出

Connected to the target VM, address: '127.0.0.1:52564', transport: 'socket'
Disconnected from the target VM, address: '127.0.0.1:52564', transport: 'socket'
栈为空!
Process finished with exit code 0
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值