1

我有一种情况,如果某个值没有返回,我可能需要阻止我的 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 方法?

4

1 回答 1

3

尝试放入return;你的 catch 块。

于 2012-07-09T01:36:57.327 回答