Java try/catch performance, is it recommended to keep what is inside the try clause to a minimum?

Is it recommended to keep the lines
inside the try catch to bare minimum?

No. Can’t imagine how you could think that the length of a try block or indeed of any block can have any impact on performance.

Does the code inside the try clause
run slower or cause any performance
hit?.

No.

As you observed, exceptions only incur performance costs when thrown.

If you’re concerned about ‘try’ performance, surely the thing to do is keep the code inside to a maximum?

Leave a Comment