[英]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.