Behaviour of return statement in catch and finally

finally is always executed (the only exception is System.exit()). You can think of this behavior this way:

  1. An exception is thrown
  2. Exception is caught and return value is set to 5
  3. Finally block gets executed and return value is set to 10
  4. The function returns

It is overridden by the one in finally, because finally is executed after everything else.

That's why, a rule of thumb - never return from finally. Eclipse, for example, shows a warnings for that snippet: "finally block does not complete normally"