当前位置:网站首页>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 .
边栏推荐
- Alibaba cloud container service differentiation SLO hybrid technology practice
- Several ways to set up a blog locally [attach relevant software download links]
- Qtcharts notes (V) scatter diagram qscatterseries
- Development and application of fcitx functional plug-ins
- Double efficiency. Six easy-to-use pychar plug-ins are recommended
- China standard gas market prospect investment and development feasibility study report 2022-2028
- Make small tip
- D24:divisor and multiple (divisor and multiple, translation + solution)
- What is the Valentine's Day gift given by the operator to the product?
- Powerful blog summary
猜你喜欢
Collation of the most complete Chinese naturallanguageprocessing data sets, platforms and tools
How to make icons easily
Cannot build artifact 'test Web: War expanded' because it is included into a circular depend solution
MySQL 8.0.12 error: error 2013 (HY000): lost connection to MySQL server during query
[GNN] hard core! This paper combs the classical graph network model
BBS forum recommendation
What is the Valentine's Day gift given by the operator to the product?
Reading notes on how programs run
NLP pre training technology development
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
随机推荐
Is user authentication really simple
Powerful blog summary
【leetcode】300. Longest increasing subsequence (dynamic programming, dichotomy)
P1656 bombing Railway
What is the Valentine's Day gift given by the operator to the product?
Gossip about redis source code 79
Version rollback revert don't reset better reset must be forced
[CSDN Q & A] experience and suggestions
Gossip about redis source code 75
Gossip about redis source code 83
Selenium library 4.5.0 keyword explanation (I)
Global and Chinese market of glossometer 2022-2028: Research Report on technology, participants, trends, market size and share
The upload experience version of uniapp wechat applet enters the blank page for the first time, and the page data can be seen only after it is refreshed again
1214 print diamond
Deep learning ----- using NN, CNN, RNN neural network to realize MNIST data set processing
ITK learning notes (VII) the position of ITK rotation direction remains unchanged
[NLP] text classification still stays at Bert? Duality is too strong than learning framework
Recommendation of knowledge base management system
Gossip about redis source code 82
Solution to the impact of Remote Code Execution Vulnerability of log4j2 component on December 9, 2021