Java 如果捕获到异常,则跳过onClick的其余部分
如果某个值没有返回,我可能需要阻止onClick方法的其余部分运行:Java 如果捕获到异常,则跳过onClick的其余部分,java,android,exception,onclick,Java,Android,Exception,Onclick,如果某个值没有返回,我可能需要阻止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
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方法的其余部分?尝试放置
返回代码>在您的catch块中 您是否尝试过使用return代码>?很有趣。我不认为它可以用于取消方法体的其余部分。这就是return
关键字的全部目的。它立即返回到调用方法(带有可选的返回值)。