In this case, he is superfluous.
This is useful if, for example, you throw an exception and still want some code to run after the block:
try { // do something dangerous } catch(...) { // log the error or something throw; // let the exception bubble up to the caller } finally { // this always runs } // this only runs if there was no exception
Another example: if catch can throw an exception for another reason:
try { // do something dangerous } catch(...) { // handle the error // log the error, which may cause a different exception } finally { // this runs even if the catch crashed } // this only runs if there was no exception, or the code in the catch worked
Simple, since code can crash for many reasons that you donβt even know about, it is useful to put a cleanup in the finally block to make sure that it works no matter what happens.
Guffa source share