This is a common idiom for handling (or better: not handling) exceptions in code that allocates resources.
If an exception occurs in the try block, this block will terminate abruptly. Then the corresponding catch command will be checked. If this is not found, if the external block terminates abruptly, which in most cases means that the method will throw this exception for its caller.
But before that, the finally block will always be executed after exiting the try block (and even after processing the excluded catch). This is the best place to host any dedicated resources. This way you will make sure that you have cleared after your work whether an exception occurred or not.
source share