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!

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 trial

Java Java Basics Perfecting the Prototype Conditional ints

Still having trouble with the concept of System.exit(0);

Im having trouble with the general concept of what it is used for and why it is a 0 instead of any other digit

1 Answer

5,604 Points

Hi again, I will do my best to explain what this is. System.exit is a line of code that is used to terminate the program. It can return either a value of 0 or 1. The 0 means that the code ended as expected. A return value of 1 means that there was some sort of issue.

In practice, you generally are only going to be using System.exit if the user has input that they want to terminate the program. Using System.exit to handle an exception is generally not a good idea. We use the different types of exceptions so that when there is an issue we can catch them, and the program continues to run rather than shutting down.

Hope this helps!