I have a situation where I may need to prevent the rest of my onClick method from running if a certain value doesn't return:
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!
}
...
}
Is there a way to skip the rest of the onClick method if the exception is caught?
Try putting return;
in your catch block.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.