try
block or not. If no exception occurs in try
, but one occurs in finally
, there's nothing particularly interesting: this exception will propagate up the call stack as usual until it encounters a matching catch
.The question typically refers to the second case, where execution enters
finally
while an exception is thrown from try
. In this scenario, the exception from finally will replace the exception from try and will propagate up the stack instead. The original issue from try
will simply be forgotten.Such masking of exceptions makes debugging more difficult, and it’s best to avoid it. For example, IntelliJ IDEA provides a warning when a
throw
statement is used inside a finally
block.All the intricacies of exception flow through try-catch-finally are described in section 14.20.2 of the specification.