Mar*_*n08 7 java for-loop exception
在Java中,两者之间的区别(在性能方面):
for (int i = 0; i < count; i++) {
try {
// code that throws Exception
} catch (Exception e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
和
try {
for (int i = 0; i < count; i++) {
// code that throws Exception
}
} catch (Exception e) {
e.printStackTrace();
}
Run Code Online (Sandbox Code Playgroud)
你可以使用两者,但这一切都取决于你想要它做什么.如果你想在循环完成一次后继续执行,那么你就是第一种方式.如果你想捕获异常然后停止执行循环然后你做第二个.性能方面,这一切都取决于你想用它做什么.
| 归档时间: |
|
| 查看次数: |
16159 次 |
| 最近记录: |