The answer is that in your second example, "z" is not guaranteed to be
executed, whereas in your first example, it is.
One caveat, though. Your specific examples were a bit unrealistic: it's
bad style to simply have a "catch" without saying what to catch, a
"catch-all" if you'll pardon the pun. So the way that your examples are
written, the only way that "z" will not be executed in the second
example is if "y" throws an exception (inside the catch block).
A more realistic case would be one in which the "catch" blocks catch
specific exceptions, in which case you need "finaly" in case some other
kind of exception that you're not catching occurs.
Sometimes people (like me) even use "finally" with no "catch" at all:
we want the exceptions to percolate up to the caller, but we have to be
sure to release some resource, reset some value, or change some setting
before leaving.
In my code, changing the cursor to an hourglass is a good example:
// Change the cursor to an hourglass
try
{
.... do a long, slow, complicated operation...
}
finally
{
// Change the cursor back to the default
}
I change the cursor back to a default in the finally block because I
want that to happen _even if_ the complex operation inside the "try"
blows up. In fact, the operation is complex enough that it has already
blown up on me several times for reasons beyond my control. If my
"Change the cursor back" code weren't within the "finally" then my
cursor would be stuck as an hourglass.