What are the rules for using try/catch statements, as opposed to just throwing an Exception and within the method declaration adding “throws Exception” ?
Should the try/catch just be for the client code and the “throws Exception” be within the API methods?
The general logic with checked exceptions is – if you can take measures in the exceptional situation, do so. Otherwise – rethrow up.
Note that
throws Exceptionshould be avoided, but I’ll assume you meanthrow SomeException– be as concrete as possible.The real benefit of checked exceptions is limited, but they are overused. That leads to (in many cases justified) simply wrapping them in an unchecked exception:
I’ve shared my thoughts on the matter here.