Alex Rivera | Logout

Difference in System. exit(0) , System.exit(-1), System.exit(1 ) in Java

Asked 2010-03-12T17:33:31.447
312

I'd like to know the difference between the following in Java

System.exit(0);
System.exit(-1);
System.exit(1);

When do I have to use the above code appropriately?

Edit
Report

1 Answer

142

Zero => Everything Okay

Positive => Something I expected could potentially go wrong went wrong (bad command-line, can't find file, could not connect to server)

Negative => Something I didn't expect at all went wrong (system error - unanticipated exception - externally forced termination e.g. kill -9)

(values greater than 128 are actually negative, if you regard them as 8-bit signed binary, or twos complement)

There's a load of good standard exit-codes here

answered 2012-11-06T08:42:37.957

Your Answer