小编Mr.*_*ite的帖子

try-catch块的位置是否会影响性能?

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)

从逻辑上讲,这两个例子是等价的,但我更喜欢哪个?

java performance try-catch

6
推荐指数
1
解决办法
2718
查看次数

标签 统计

java ×1

performance ×1

try-catch ×1