Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个称为test()抛出异常的方法。
test()
我想编写一个循环,只要它抛出异常就执行,并在它不再抛出异常时中断。
任何人都可以提示我必须使用的逻辑吗?
例如我试过,
int i=0; while(test()) { i++; } System.out.println(i);
int i=0; while (true) { try { test(); break; } catch (Exception e) { i++; // Loop will continue } }