Difference between System. exit (0) and System. exit (1), difference between system. exit
1. References
Http://hi.baidu.com/accpzhangbo/blog/item/52aeffc683ee6ec238db4965.html
2. Parsing
Check the source code of java. lang. System. We can find the description of the method System. exit (status). The Code is 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); }
This method is used to end the currently running Java VM. If status is a non-zero parameter, it indicates that the system exits abnormally.
3. Example
In an if-else judgment, if our program is executed as expected and we need to stop the program at the end, then we use System. exit (0), while System. exit (1) is usually placed in the catch Block. When an exception is caught and the program needs to be stopped, we use System. exit (1 ). This status = 1 indicates that the program exits abnormally.
This article