try-catch块的位置是否会影响性能?
例1:while-loop 内部的 try-catch块
while (true) {
try {
// ... read from a file
} catch (EOFException e) {
break;
}
}
Run Code Online (Sandbox Code Playgroud)
例2:try-catch块环绕 while循环
try {
while (true) {
// ... read from a file
}
} catch (EOFException e) {
// :P
}
Run Code Online (Sandbox Code Playgroud)
从逻辑上讲,这两个例子是等价的,但我更喜欢哪个?