发生错误时我想尝试 3 次。到目前为止我所做的......
public class TryTest {
public static void main(String[] args) {
TryTest test = new TryTest();
test.tryThis();
}
public void tryThis() {
int a = 10;
int x = 0;
int count = 1;
try {
System.out.println("Test " + count);
a = a / x;
System.out.println("Success !");
} catch (Exception e) {
if (count <= 3) {
// I want to try again with new x value
count++;
x++;
}
System.out.println("ERROR:\t" + e);
} finally {
System.out.println("Finish");
}
}
}
我怎样才能做到这一点?