Java application return codes

Posted by doele on Stack Overflow See other posts from Stack Overflow or by doele
Published on 2010-05-05T22:28:54Z Indexed on 2010/05/05 22:38 UTC
Read the original article Hit count: 101

Filed under:
|

I have a Java program that processes one file at a time. This Java program is called from a wrapper script which logs the return code from the Java program. There are 2 types of errors. Expected errors and unexpected errors. In both cases I just need to log them. My wrapper knows about 3 different states. 0-OK, 1-PROCESSING_FAILED, 2- ERROR.

Is this a valid approach?

Here is my approach:

enum ReturnCodes {OK,PROCESSING_FAILED,ERROR};

    public static void main(String[] args)
    {
        ...
            proc.processMyFile();
        ...
        System.exit(ReturnCodes.OK.ordinal());
    }
    catch (Throwable t)
    {
        ...
        System.exit(ReturnCodes.ERROR.ordinal());
    }


private void processMyFile()
{
    try
    {
        ...
    }catch( ExpectedException e)
    {
        ...
        System.exit(ReturnCodes.PROCESSING_FAILED.ordinal());
    }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about exception