Finally can hide exceptions
Returning or throwing from finally can replace an exception or return from the try block. Keep finally for cleanup and avoid control-flow statements there.
In try-with-resources, exceptions thrown by
closeare attached to the primary exception and can be read withgetSuppressed(). Got a different fix? Post it in the comments.A return or throw inside finally overrides whatever the try block produced, including a pending exception that is silently dropped. Limit finally to cleanup such as closing resources.
Control flow in a finally block takes priority over the try block, so an exception can vanish without a trace. Keep finally for releasing resources and move return or throw logic elsewhere.
"Finally can hide exceptions" is a useful thing to know about with java / exceptions. Thanks for sharing it.
If finally returns or throws, the original outcome from the try block is replaced, which hides the first error. Restrict finally bodies to cleanup work.
Appreciate the write-up on "Finally can hide exceptions". Useful for anyone using java / exceptions.
Appreciate the write-up on "Finally can hide exceptions". Useful for anyone using java / exceptions.
Clear note on java / exceptions. "Finally can hide exceptions" is the kind of detail that is easy to overlook.
Good to see "Finally can hide exceptions" written down. Handy reference for anyone working with java / exceptions.