Try Catch vs If Else
<p>Which of the following code is better to implement</p>

<pre><code>public string myfunc(JSONArray funcargs){

    int ctxHandle;
    String StringParam=null;
    JSONObject jObj=null;

    try {
        ctxHandle = funcargs.getInt(2);
        if(funcargs.length() == 4) {
            try {
                StringParam = funcargs.getString(3);
            } catch (JSONException jsonEx) {
                jObj = funcargs.getJSONObject(3);
            }
        }
    } catch (JSONException jsonEx) {
        SendJS = "javascript:" + FailureCallBack + "('" + jsonEx.getMessage() + "')"; 
        sendJavascript(SendJS);
        return null;
    }

    //This will return an integer
    ret_val = get_data(ctxHandle);
    SendJS = "javascript:" + SuccessCallBack + "('" + Integer.toString(ret_val);
    if(StringParam != null)
        SendJS  += "','" + StringParam + "')";
    else if(jObj != null)
        SendJS  += "','" + jObj + "')";
    else 
        SendJS  += "')";

    sendJavascript(SendJS);
    return null;
}
</code></pre>

<p>OR </p>

<pre><code>public string myfunc(JSONArray funcargs){

    int ctxHandle;
    String StringParam=null;
    JSONObject jObj=null;

    try{
        ctxHandle = funcargs.getInt(2);
        //This will return an integer
        ret_val = get_data(ctxHandle);
        SendJS = "javascript:" + SuccessCallBack + "('" + Integer.toString(ret_val);
        if(funcargs.length() == 4) {
            try {
                StringParam = funcargs.getString(3);
                SendJS  += "','" + StringParam + "')";
            } catch (JSONException jsonEx) {
                jObj = funcargs.getJSONObject(3);
                SendJS  += "','" + jObj + "')";
            }
            SendJS  += "')";
        }
    } catch (JSONException jsonEx) {
        SendJS = "javascript:" + FailureCallBack + "('" + jsonEx.getMessage() + "')"; 
    }

    sendJavascript(SendJS);
    return null;                        
}
</code></pre>

<p>Personally from <a href="http://stackoverflow.com/questions/8621762/java-if-vs-try-catch-overhead">Java if vs. try/catch overhead</a> Thread I understand that <code>try/catch</code> should be used only in the cases where you are uncertain of the result and an exception can be handled but the if else if can be saved argument generates some doubt although putting the entire code in a try catch block somehow does not make sense to me.</p>

<p>Need help on this.      </p>
