Can any one share to me difference between System.exit(0)
and System.exit(-1)
it is helpful if you explain with example.
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.
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.
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.
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.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With