0

I have created a JAR file named "FileProcessor.jar" which consist of:

public class FileProcessor{
    public static void main(String[] args){
        try{
            // logic
        }catch(Exception ex){
        // catch logic
        }
    }
}

I need to run different logic according to the output of the jar file. If an exception arises I need to call a different jar file.

Tuse
  • 1
  • 3

1 Answers1

1

In the simplest shape this could be done like this:

try{
  // logic
}
catch(Exception ex){
  System.exit( 1 );
}
System.exit( 0 );

In the batch do:

@echo off
java -jar ...
if errorlevel 1 goto runother
if errorlevel 0 goto allok
...

Please remember that if errorlevel has an implicit "greater than or equal". If the JVM crashes it sets an exit code on its own, you can read more about it here: Is there a complete List of JVM exit codes

Marged
  • 10,577
  • 10
  • 57
  • 99