Catch Java exception in MS-DOS Batch File

Hello,

I am new to java programming. I have written a program which reads a file and create multiple files based on certain condition. I am executing my java executable from a MS-DOS Batch file.

I have a situation whereby I want to move these newly created file to a new folder/directory by executing the MS-DOS command in the batch file.

Now the issue is I want to be sure if the java class has been executed successfully then only I want to execute the subsequent command in the Batch file. Is there a way to catch the program exception in the MS-DOS Batch file and based on the exit code execute the next command in the Batch file.

Any help is much appreciated.

Best Reagrds

pastha

[728 byte] By [pasthaa] at [2007-11-27 7:12:59]
# 1
Yes, use System.exit(myErrorValue) to return a value back to your caller.
morgalra at 2007-7-12 19:03:55 > top of Java-index,Java Essentials,Java Programming...
# 2

You can specify an error code before exiting a java application using

System.exit(int);

The int passed to this is the error code usually zero means no errors

Using batch file you can retrieve this value using the ERRORLEVEL environment variable

Example

echo %ERRORLEVEL%

WirajRa at 2007-7-12 19:03:55 > top of Java-index,Java Essentials,Java Programming...
# 3
Thanks for the replyWhat if I get an error "java.lang.NoClassDefFoundError" will the "error code" be updated by the system. This error can hapen if somebody change the Classpath.Best Regards
pasthaa at 2007-7-12 19:03:55 > top of Java-index,Java Essentials,Java Programming...