Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

difference between System.exit(0) and System.exit(-1) [duplicate]

Can any one share to me difference between System.exit(0) and System.exit(-1) it is helpful if you explain with example.

like image 939
ramana Avatar asked Aug 04 '11 07:08

ramana


People also ask

What is the difference between system exit 0 and system exit 1?

exit function has status code, which tells about the termination, such as: exit(0) : Indicates successful termination. exit(1) or exit(-1) or any non-zero value – indicates unsuccessful termination.

What does system exit 0 mean?

Exiting with a code of zero means a normal exit: System. exit(0); We can pass any integer as an argument to the method. A non-zero status code is considered as an abnormal exit.

What is the difference between exit 0 and exit 1 in Python?

The function calls exit(0) and exit(1) are used to reveal the status of the termination of a Python program. The call exit(0) indicates successful execution of a program whereas exit(1) indicates some issue/error occurred while executing a program.

What is difference between return and system exit 0 in Java?

return statement is used inside a method to come out of it. System. exit(0) is used in any method to come out of program. System.


1 Answers

It's just the difference in terms of the exit code of the process. So if anything was going to take action based on the exit code (where 0 is typically success, and non-zero usually indicates an error) you can control what they see.

As an example, take this tiny Java program, which uses the number of command line arguments as the exit code:

public class Test {    
    public static void main(String[] args) throws Exception {
        System.exit(args.length);
    }
}

Now running it from a bash shell, where && means "execute the second command if the first one is successful" we can have:

~ $ java Test && echo Success!
Success!

~ $ java Test boom && echo Success!
like image 110
Jon Skeet Avatar answered Sep 28 '22 03:09

Jon Skeet