Does the placement of a try-catch block affect performance?
EXAMPLE 1: try-catch block inside of the while-loop
while (true) { try { // ... read from a file } catch (EOFException e) { break; } } EXAMPLE 2: try-catch block surrounds the while-loop
try { while (true) { // ... read from a file } } catch (EOFException e) { // :P } Logically, these two examples are equivalent, but which should I prefer?
break;Either your program won't compile, or you'll be breaking out of the wrong loop.@krock:I was waiting for someone to say this; at a high-level, it's equivalent in my code. I'll post a complete code example later, but hopefully you understood the question.@all:The second break was a mistake from copy/paste.