[Effective Java] Item 9 – Prefer try-with-resources to try-finally

Published by

on

It is recommended to use try-with-resources rather than try-finally when we are working with resources that need to be closed as the resulting code is much shorter and cleaner, and the exceptions that is generates are more useful.

Usage of try-with-resources

Note that we can use catch clause from try-with-resources as well.

Leave a comment