次のコードのうち、実装するのに適しているのはどれですか
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;
}
また
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;
}
個人的には、Java if vs. try/catch オーバーヘッドスレッドからtry/catch
、結果が不確かで例外を処理できる場合にのみ使用する必要があることを理解していますが、if else if can be save 引数を使用すると、全体を入れても疑問が生じますtry catch ブロック内のコードは、どういうわけか私には意味がありません。
これについて助けが必要です。