Reputation: 81
I used exit()
in my java program and it just exits the executing program. But I don't understand the difference between types of exits!!
Such as for example
exit(0)
exit(1)
exit(2)
..so on. Can anyone share info about this?
Upvotes: 0
Views: 103
Reputation: 4252
A non zero reurn code indicates abnormal termination (by convention). Moreover you can return different non-zero values to indicate the cause of terminating the program, so that its easier to debug/identify the error.
Look at the documentation : System class
Upvotes: 2
Reputation: 11026
That is called the exit status or return code. It tells the shell whether your program ran without error (return code 0
) or with an error (any other return code value, which one you choose indicates the type of error.)
Upvotes: 2
Reputation: 12744
The value means nothing for the Java program itself. The shell calling the Java program can use it to determine what to do next.
From JavaDoc public static void exit(int status)
terminates the currently running Java Virtual Machine. The argument serves as a status code
; by convention, a nonzero status code indicates abnormal termination.
Upvotes: 6