频道栏目
首页 > 资讯 > 其他 > 正文

System的exit测试方法作用

17-11-30        来源:[db:作者]  
收藏   我要投稿

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.
     * 

* This method calls the exit method in class * Runtime. This method never returns normally. *

* The call System.exit(n) is effectively equivalent to * the call: *


     * Runtime.getRuntime().exit(n)
     * 
* * @param status exit status. * @throws SecurityException * if a security manager exists and its checkExit * 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
相关TAG标签
上一篇:JS事件对象(event)讲解(代码实例)
下一篇:SSM框架搭建入门学习
相关文章
图文推荐

关于我们 | 联系我们 | 广告服务 | 投资合作 | 版权申明 | 在线帮助 | 网站地图 | 作品发布 | Vip技术培训 | 举报中心

版权所有: 红黑联盟--致力于做实用的IT技术学习网站