Regarding your second question... When a module throws a checked exception it "assumes" that its client must be forced to do something about it. Generally, it is very rare when you can safely and justifiably make such assumption. It is more appropriate to simply make the information available for those who are interested in it - without
forcing it on
everybody. So, unless you are putting together a very tight sub-system where you are 100% sure that if A calls B then A
must handle exceptions inside B, then checked exceptions will do the job by forcing A to do something. In a vast majority of cases (especially, in the case of frameworks and services that are designed to be used by different clients in potentially different contexts) it is not appropriate to force the
immediate caller to handle the exception because the exception most likely should propagate to a handler further up the call stack. At the same time, a specific exception in the method signature is an implementation detail of the method. Consider a typical example: A calls B, and B calls C on some generic service, and C declares a checked exception. B does not know what to do with that exception, so the only correct thing to do is to propagate it to A and let A decide whether it can handle it. The simplest thing is to add that exception to the signature of B without writing any try/catches. But that would expose C's implementation detail to A, and A should not even know that C exist! So, such simple delegation via adding a "throws" clause to B would be inappropriate. The only proper solution in that case would be for B to catch the exception, wrap it into a new exception that is specific to the tier in which B lives and A is aware of (since A is aware of B), and then re-throw. That involves unnecessary useless code clutter - for no reason - since B couldn't do anything about the exception anyway. If the re-thrown exception is checked, the whole thing has to be repeated in A, and so on... That is why, in most cases, the cleanest thing you can do is to throw a RTE and let those who are interested decide for themselves. Yes, the responsibility is still on the programmer, no one has changed that. But it is easy to detect unhandled RTEs and their origins - unlike chasing subtle problems caused by mishandled checked exceptions. One thing you should remember: all methods may fail, not only those that throw checked exceptions. It may sound like a revelation to some folks who were raised on checked exceptions, but it is a very simple fact of life. And when you know that anything may fail, RTEs are working for you, not against.
That said, there are still a lot of people who defend the wider use of checked exceptions. I have expressed
my professional opinion.
Hope this helps.
Constantine