博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java 中的System.exit
阅读量:7072 次
发布时间:2019-06-28

本文共 1155 字,大约阅读时间需要 3 分钟。

在java 中退出程序,经常会使用System.exit(1) 或 System.exit(0)。 

 

查看System.exit()方法的源码,如下

 

1   /** 2      * Terminates the currently running Java Virtual Machine. The 3      * argument serves as a status code; by convention, a nonzero status 4      * code indicates abnormal termination. 5      * 

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

9 * The call System.exit(n) is effectively equivalent to10 * the call:11 *

12      * Runtime.getRuntime().exit(n)13      * 
14 *15 * @param status exit status.16 * @throws SecurityException17 * if a security manager exists and its checkExit18 * method doesn't allow exit with the specified status.19 * @see java.lang.Runtime#exit(int)20 */21 public static void exit(int status) {22 Runtime.getRuntime().exit(status);23 }

  当 status为0 时正常退出程序, 当status为非0数字时异常退出。 终止当前的Java虚拟机。 

 

System.exit()方法返回程序的最顶层, return和它相比是返回上一层。 

 

当程序执行到System.exit()方法后就会停止运行。 如果希望程序遇到System.exit后只退出当前用例,不退出当前程序,可以考虑在异常中做手脚。

 

转载于:https://www.cnblogs.com/Theladyflower/p/4018417.html

你可能感兴趣的文章
这家AI芯片独角兽吊打英伟达,吹捧还是硬实力?
查看>>
寒冬下2年android的搞笑求职历程
查看>>
19.Shell编程进阶,数组,字符串,(for,select,while read line)
查看>>
怎样快速将文字转换成语音?这种操作很简单
查看>>
Oracle 树操作 (select…start with…connect by…prior)
查看>>
重新打开MyEclipse 后,发现SVN 不能用了,而且是引用直接失效问题
查看>>
ios 禁止横屏
查看>>
【非凡程序员】  OC第十一节课 (代码块)
查看>>
Java正则表达式详解(三)
查看>>
无线网络布署方式
查看>>
loadrunner 乱码问题设置总结
查看>>
php安装redis 和redis扩展
查看>>
Javascript将html转成pdf,下载(html2canvas 和 jsPDF)
查看>>
org.apache.jasper.jasperException
查看>>
详解 ML2 Core Plugin(I) - 每天5分钟玩转 OpenStack(71)
查看>>
week03_python解析式
查看>>
盘点中国未来最具潜力的IT培训学校前5名
查看>>
php5.4.26 安装出现 error: ‘struct gdIOCtx’ has no member named ‘data’
查看>>
java 后端简单分页
查看>>
局域网安全6 ARP***
查看>>