当前位置:网站首页>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 .
边栏推荐
- [2021]NeRF in the Wild: Neural Radiance Fields for Unconstrained Photo Collections
- How to write a good title of 10w+?
- [about text classification trick] things you don't know
- Gossip about redis source code 79
- Shell script three swordsman sed
- A Kuan food rushed to the Shenzhen Stock Exchange: with annual sales of 1.1 billion, Hillhouse and Maotai CCB are shareholders
- NLP pre training technology development
- Gossip about redis source code 82
- Global and Chinese markets for instant saliva testing devices 2022-2028: Research Report on technology, participants, trends, market size and share
- Kubedl hostnetwork: accelerating the efficiency of distributed training communication
猜你喜欢

NLP Chinese corpus project: large scale Chinese natural language processing corpus

Unity elementary case notes of angry birds Siki college 1-6

Joint examination of six provinces 2017

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

Regular expressions and text processors for shell programming

Idea set class header comments

Introducing Software Testing

Private project practice sharing populate joint query in mongoose makes the template unable to render - solve the error message: syntaxerror: unexpected token r in JSON at
![Several ways to set up a blog locally [attach relevant software download links]](/img/2f/51a09d9ef71065319ed90306517854.jpg)
Several ways to set up a blog locally [attach relevant software download links]

Zipper table in data warehouse (compressed storage)
随机推荐
[Mongodb] 2. Use mongodb --------- use compass
Zipper table in data warehouse (compressed storage)
Ningde times and BYD have refuted rumors one after another. Why does someone always want to harm domestic brands?
What are the application fields of digital twins in industry?
Shell script three swordsman sed
Selenium check box
2022 examination of safety production management personnel of hazardous chemical production units and examination skills of safety production management personnel of hazardous chemical production unit
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
Alibaba cloud container service differentiation SLO hybrid technology practice
Investment demand and income forecast report of China's building ceramics industry, 2022-2028
Make small tip
[C language] break and continue in switch statement
2022 chemical automation control instrument examination content and chemical automation control instrument simulation examination
It is the most difficult to teach AI to play iron fist frame by frame. Now arcade game lovers have something
EPF: a fuzzy testing framework for network protocols based on evolution, protocol awareness and coverage guidance
Gossip about redis source code 75
Global and Chinese market of process beer equipment 2022-2028: Research Report on technology, participants, trends, market size and share
D25:sequence search (sequence search, translation + problem solving)
炒股開戶傭金優惠怎麼才能獲得,網上開戶安全嗎
P1339 [USACO09OCT]Heat Wave G