Exiting from your program

Introduction

If you need to exit from a running program, you can do it with the System.exit() command. The parameter of exit should qualify if the execution of the program went good or bad. It’s a sort of heredity from older programming languages where it’s useful to know if something went wrong and what went wrong.

// No errors
int errorCode = 0;

// An error occurred
errorCode = -1;

// Terminate
System.exit(errorCode);

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.