Eveything that is enclosed in your finally block is ensured to be executed, and it could be useful in these 2 concrete cases at least :
- Sometimes you decide to call
return
in the middle of your try block and get back to the caller :finally
ease the process of releasing ressources here, you don't have to write some specific code to go directly to the end of your method. - Sometimes you want to let an exception go up (by not catching it) and maybe being caught at a higher level (because it is not the appropriate place to handle it properly for example). Again
finally
ensures your resources are released and the exception continue its path.
Maybe you can see finally
as a tool helping developpers to do things they're obliged to do with less effort. On the other side, catch
is dedicated to handle errors.
Both keywords are dedicated to flow control, but they don't have the same purpose and they can be used one without each other (and often are!). It depends on your needs.