当前位置:网站首页>system. Exit (0) and system exit(1)
system. Exit (0) and system exit(1)
2022-07-04 00:19:00 【Hello】
One 、 sketch
java.lang.System Source code , The method is described as follows :
/** * 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);
}
Both are used to end the currently running JVM, Exiting the program means , If status Is a non-zero parameter , Then it means an abnormal exit .
difference :
system.exit(0): After the normal execution of the program, exit . The method is to stop the content in the whole virtual machine , and dispose() Just close this window , But it didn't stop the whole application exit() . in any case , Memory is free . In other words, even JVM It's all closed , There can't be anything else in memory .system.exit(1): Abnormal exit , That is, whether the program is executing or not , All quit .1 Or not 0 Indicates abnormal exit procedure . No matter status Why do all values exit the program .return Is to go back to the upper level , and System.exit(status) Is to go back to the top .
Two 、 usage
stay if-else In judgment , If the program performs as expected , In the end, you need to stop the program , So use System.exit(0). and System.exit(1) Generally placed on catch block in , When an exception is caught , Used to stop the program . This status=1 Is used to indicate that the program exits abnormally .
边栏推荐
- Gossip about redis source code 78
- Kubedl hostnetwork: accelerating the efficiency of distributed training communication
- 2022 free examination questions for hoisting machinery command and hoisting machinery command theory examination
- ISBN number
- 2022 system integration project management engineer examination knowledge points: software development model
- CSP window
- D26: the nearest number (translation + solution)
- AI Challenger 2018 text mining competition related solutions and code summary
- Zipper table in data warehouse (compressed storage)
- Pytorch learning notes 5: model creation
猜你喜欢
![[MySQL] classification of multi table queries](/img/96/2e51ae8d52ea8184945e0540ce18f5.jpg)
[MySQL] classification of multi table queries

Alibaba cloud container service differentiation SLO hybrid technology practice

Qtcharts notes (V) scatter diagram qscatterseries

leetcode-43. String multiplication

It is the most difficult to teach AI to play iron fist frame by frame. Now arcade game lovers have something

2022 free examination questions for hoisting machinery command and hoisting machinery command theory examination

A Kuan food rushed to the Shenzhen Stock Exchange: with annual sales of 1.1 billion, Hillhouse and Maotai CCB are shareholders

Celebrate the new year | Suihua fire rescue detachment has wonderful cultural activities during the Spring Festival

BBS forum recommendation

Axure resources and prototype tool Axure RP 9 download
随机推荐
Selenium library 4.5.0 keyword explanation (II)
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
I wrote a chat software with timeout connect function
Selenium library 4.5.0 keyword explanation (I)
No qualifying bean of type ‘com. netflix. discovery. AbstractDiscoveryClientOptionalArgs<?>‘ available
Yyds dry goods inventory three JS source code interpretation - getobjectbyproperty method
2022 chemical automation control instrument examination content and chemical automation control instrument simulation examination
P1656 bombing Railway
Investment demand and income forecast report of China's building ceramics industry, 2022-2028
Analysis: misunderstanding of choosing WMS warehouse management system
[BSP video tutorial] stm32h7 video tutorial phase 5: MDK topic, system introduction to MDK debugging, AC5, AC6 compilers, RTE development environment and the role of various configuration items (2022-
How to write a good title of 10w+?
Vscode regular match replace console log(.*)
Kubedl hostnetwork: accelerating the efficiency of distributed training communication
Speed up the energy Internet of things. What can low-power Internet of things technology represented by Zeta do?
网上的低佣金链接安全吗?招商证券怎么开户?
Minimum commission for stock account opening. Stock account opening is free. Is online account opening safe
Make small tip
JDBC Technology
1214 print diamond