当前位置:网站首页>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 .
边栏推荐
- Distributed transaction -- middleware of TCC -- selection / comparison
- Test the influence of influent swacth on the electromagnetic coil of quartz meter
- Research Report on the scale prediction of China's municipal engineering industry and the prospect of the 14th five year plan 2022-2028
- STM32 key light
- Make small tip
- D28:maximum sum (maximum sum, translation)
- Global and Chinese markets of distributed control system (DCS) consumption 2022-2028: Research Report on technology, participants, trends, market size and share
- P1629 postman delivering letter
- Docking Alipay process [pay in person, QR code Payment]
- Powerful blog summary
猜你喜欢
Recommendation of knowledge base management system
The interviewer's biggest lie to deceive you, bypassing three years of less struggle
2022 Guangdong Provincial Safety Officer a certificate third batch (main person in charge) simulated examination and Guangdong Provincial Safety Officer a certificate third batch (main person in charg
[2021]NeRF in the Wild: Neural Radiance Fields for Unconstrained Photo Collections
Deep learning ----- using NN, CNN, RNN neural network to realize MNIST data set processing
URL (data:image/png; Base64, ivborw0k... Use case
Entropy and full connection layer
The first game of the new year, many bug awards submitted
Zipper table in data warehouse (compressed storage)
Vscode regular match replace console log(.*)
随机推荐
[about text classification trick] things you don't know
What is the difference between NFT, SFT and dnft? How to build NFT platform applications?
The first game of the new year, many bug awards submitted
Investment demand and income forecast report of China's building ceramics industry, 2022-2028
Subgraph isomorphism -subgraph isomorphism
Version rollback revert don't reset better reset must be forced
Selenium library 4.5.0 keyword explanation (II)
[source code] VB6 chat robot
Amway by head has this project management tool to improve productivity in a straight line
Comment obtenir une commission préférentielle pour l'ouverture d'un compte en bourse? Est - ce que l'ouverture d'un compte en ligne est sécurisée?
leetcode-43. String multiplication
JDBC Technology
Analysis of refrigeration and air conditioning equipment operation in 2022 and examination question bank of refrigeration and air conditioning equipment operation
Vscode regular match replace console log(.*)
Gossip about redis source code 78
Development and application of fcitx functional plug-ins
1214 print diamond
[GNN] hard core! This paper combs the classical graph network model
Report on prospects and future investment recommendations of China's assisted reproductive industry, 2022-2028 Edition
Analysis on the scale of China's smart health industry and prediction report on the investment trend of the 14th five year plan 2022-2028 Edition