Why are try blocks expensive?

It’s not the block itself that’s expensive, and it’s not even catching an exception, per se, that’s expensive, it’s the runtime unwinding the call stack until it finds a stack frame that can handle the exception. Throwing an exception is pretty light weight, but if the runtime has to walk up six stack frames (i.e. six method calls deep) to find an appropriate exception handler, possibly executing finally blocks as it goes, you may see a noticeable amount of time passed.

Leave a Comment