[英]Skip rest of onClick if exception is caught
我有一種情況,如果某個值沒有返回,我可能需要阻止我的onClick方法的其余部分運行:
public void onClick(View v) {
double a = 0;
double b = 0;
double c = 0;
try {
a = Double.parseDouble(((EditText) getView().findViewById(R.id.area_a)).getText().toString());
b = Double.parseDouble(((EditText) getView().findViewById(R.id.area_b)).getText().toString());
c = Double.parseDouble(((EditText) getView().findViewById(R.id.area_c)).getText().toString());
} catch (NumberFormatException e) {
//Exception here! Do not continue with the rest of the onClick method!
}
...
}
如果捕獲到異常,有沒有辦法跳過onClick方法的其余部分?
嘗試return;
在你的阻止塊。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.