Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJan Satsatin
422 PointsWhy do we put zero "0" on the "System.exit(0);" statement? Is 0 means yes and 1 is no?
Usage of zero
1 Answer
Steven Parker
231,271 Points0 means normal. Anything else is a code indicating what kind of error occurred.
Declaration
public static void exit(int status)
Parameters
status -- This is the exit status. By convention, a nonzero status code indicates abnormal termination.
Jan Satsatin
422 PointsJan Satsatin
422 PointsAnything else means we can assign return value to state what error occurred?
A X
12,842 PointsA X
12,842 PointsSteven Parker : Wouldn't we potentially forcing a normal status on something that might be running abnormally otherwise by placing System.exit(0) within our code? Wouldn't it be better to run it and determine what, if any, errors emerge?
Steven Parker
231,271 PointsSteven Parker
231,271 PointsYou would only call exit and pass 0 if you intend for the program to end at that point. That means it's a normal ending.
If the program exits because of some error, it will not reach your normal exit call, and the system will give it a non-zero return code automatically.