How do the try, catch and finally blocks interact?
The three blocks always run in a fixed order, and once you know that order most questions about them answer themselves.
The try block runs first. If it finishes without throwing anything, the catch block is skipped completely and the finally block runs next. If the try block does throw something, the catch block receives that value, and the finally block runs after it. The finally block runs on every path through the statement, whether the code succeeded, threw an error, or returned early.
Two details surprise people the first time they meet them. A return inside the try block does not skip the finally block. The return value is worked out first, but the finally block still runs before the function actually goes back to its caller, and if the finally block returns or throws, that result wins. The catch block is also optional. A try with a finally and no catch is perfectly valid, and it is the right shape for cleanup that must happen whether or not something went wrong.
You also have to think about what the finally block is allowed to do to the result. It can hide an error just by returning normally, because that turns a thrown exception into an ordinary return. That is worth doing on purpose when a failure is expected and can be recovered from. It can also swap one error for a different one by throwing from inside it, which is occasionally useful when you want to turn a low-level failure into a failure that means something in your own code.