Хотя try/catch
в while
хорошо известна и хорошая стратегия, я хочу предложить вам рекурсивный вызов:
void retry(int i, int limit) {
try {
} catch (SomeException e) {
// handle exception
if (i >= limit) {
throw e; // variant: wrap the exception, e.g. throw new RuntimeException(e);
}
retry(i++, limit);
}
}