For various reasons calling System.exit is frowned upon when writing Java Applications, so how can I notify the calling process that not everything is going according to plan?
Edit: The 1 is a standin for any non-zero exit code.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The use of
System.exitis frowned upon when the ‘application’ is really a sub-application (e.g. servlet, applet) of a larger Java application (server): in this case theSystem.exitcould stop the JVM and hence also all other sub-applications. In this situation, throwing an appropriate exception, which could be caught and handled by the application framework/server is the best option.If the java application is really meant to be run as a standalone application, there is nothing wrong with using
System.exit. in this case, setting an exit value is probably the easiest (and also most used) way of communicating failure or success to the parent process.