Hi all,
I have a program, which is invoked from a shell script. I need to return back to the shell script a status, whether the program succeeded or failed, so the shell script determines whether to continue with its normal course of actions or to stop upon faileur.
So, here's what I am assuming, and please do correct me if I am wrong.
I am planning to catch all the possible exceptions and upon catching each one, and properly handeling, I do a System.exit(2). Besides, at the very end of program flow, I do a System.exit(0).
So, in the shell script, I will check the value of $? by echoing it, and if it is 0, then the program ran successfully, else, there was some problems.
public class HelloWorld {
public static void main( String[] args ) {
try {
callFirstMethod();
callSecondMethod();
System.exit(0);
} catch (Exception e) {
e.printStackTrace();
System.exit(2);
}
}
is my theory correct? please comment.
Thanks.