I's like to add my own 0.02c
about two competing considerations when looking at the general problem of where to position exception handling:
The "wider" the responsibility of the try-catch
block (i.e. outside the loop in your case) means that when changing the code at some later point, you may mistakenly add a line which is handled by your existing catch
block; possibly unintentionally. In your case, this is less likely because you are explicitly catching a NumberFormatException
The "narrower" the responsibility of the try-catch
block, the more difficult refactoring becomes. Particularly when (as in your case) you are executing a "non-local" instruction from within the catch
block (the return null
statement).