How to return non-zero exit codes if Java file throws exceptions
<p>I am using below script(.sh file) to run a java code in an UNIX system,but even if Java is giving exception or terminated successfully in both cases,
exit code coming as 0, I want to return non zero exit codes from script, if Java run throwing an exception, so that I can add if-then check in script,to print success or failure messages.</p>

<pre><code>#!/bin/sh
echo 'processing started --&gt;&gt;'
LOC=/opt/appl/Mapping/

export JAVA_HOME=/usr/java6
export PATH=/usr/java6/bin

LD_LIBRARY_PATH=/opt/appl/JARS/

export LD_LIBRARY_PATH

java -classpath  $LOC/ojdbc6-11.2.0.3.0.jar:$LOC/ds35-02.00.11.jar:$LOC/log4j-1.2.17.jar:$LOC/TestClasses.jar:$LOC/db2jcc_license_cisuz-3.0.0.jar:$LOC/db2jcc_license_cu-3.0.0.jar:$LOC/db2jcc-3.0.0.jar -Xms256M -Xmx512M com.home.backfill.TestRun
</code></pre>

<p>I can use Try-catch in Java file and use <code>System.exit(1)</code> at catch block, but I am looking for any good generic approach, as My code could be very long, not sure if it would be good idea to put <code>System.exit(1)</code> in every catch block.</p>