当前位置:网站首页>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 .
边栏推荐
- What are the application fields of digital twins in industry?
- Selenium library 4.5.0 keyword explanation (III)
- Powerful blog summary
- Idea a method for starting multiple instances of a service
- Zipper table in data warehouse (compressed storage)
- 2022 system integration project management engineer examination knowledge points: software development model
- Gossip about redis source code 73
- Ramble 72 of redis source code
- It is forbidden to splice SQL in code
- Distributed transaction -- middleware of TCC -- selection / comparison
猜你喜欢
2022 t elevator repair registration examination and the latest analysis of T elevator repair
The interviewer's biggest lie to deceive you, bypassing three years of less struggle
Shell script three swordsman sed
How will the complete NFT platform work in 2022? How about its core functions and online time?
EPF: a fuzzy testing framework for network protocols based on evolution, protocol awareness and coverage guidance
Qtcharts notes (V) scatter diagram qscatterseries
Bodong medical sprint Hong Kong stocks: a 9-month loss of 200million Hillhouse and Philips are shareholders
Yyds dry goods inventory three JS source code interpretation - getobjectbyproperty method
It is forbidden to splice SQL in code
The first game of the new year, many bug awards submitted
随机推荐
Selenium check box
D28:maximum sum (maximum sum, translation)
D23:multiple of 3 or 5 (multiple of 3 or 5, translation + solution)
Analysis: misunderstanding of choosing WMS warehouse management system
Advanced C language - pointer 2 - knowledge points sorting
Global and Chinese market of underwater bags 2022-2028: Research Report on technology, participants, trends, market size and share
Introducing Software Testing
Idea integrates Microsoft TFs plug-in
Test the influence of influent swacth on the electromagnetic coil of quartz meter
Subgraph isomorphism -subgraph isomorphism
[Mongodb] 2. Use mongodb --------- use compass
Analysis of refrigeration and air conditioning equipment operation in 2022 and examination question bank of refrigeration and air conditioning equipment operation
Selenium library 4.5.0 keyword explanation (4)
Development and application of fcitx functional plug-ins
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
The first game of the new year, many bug awards submitted
[2021]NeRF in the Wild: Neural Radiance Fields for Unconstrained Photo Collections
(Video + graphics and text) introduction to machine learning series - Chapter 4 naive Bayes
How can I get the Commission discount of stock trading account opening? Is it safe to open an account online
Global and Chinese markets of distributed control system (DCS) consumption 2022-2028: Research Report on technology, participants, trends, market size and share