Difference between System. exit (0) and System. exit (1), difference between system. exit

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.