So I know that a finally
block of code will execute regardless of an exception, but is it bad to not use it? I've been using just try/catch
and wanted to know if this was a bad practice. Or does it not really matter?
If you don't have anything you need to clean up at the end, that's perfectly fine. finally
blocks are almost always about resource cleanup... and there are plenty of times where you want to catch an exception but don't have any resources to clean up.
Having said that, only catch exceptions when you can actually handle them or want to wrap them in a more suitable type. My experience is that catch blocks should be far rarer than try/finally or try-with-resources blocks. If you find yourself catching exceptions in most methods, that probably indicates you're misusing them.
See more on this question at Stackoverflow