in my opinion, checked exceptions are a flaw in the java design (for example, C # seems to have learned from it and offers only unverified exceptions). Sun says you should use checked exceptions if clients can recover. The problem is that, as an api developer, you just don't know which clients you can expect (-> can they recover or not?). Therefore, you should not correlate this uncertainty with your api. Therefore, I would go for excepted exceptions.
In my opinion, when you think of “reasonable client manipulations”, it often happens that in the end you pollute your api. IOException and RemoteException are notable examples of "annoying checked exceptions." In practice, they most of the time do not make sense to process clients. Of course, in rare cases, they make sense to process. Therefore, looking at this, I try to develop an api client interface and avoid the burden of checked exceptions. Of course, when using excluded exceptions, they should be documented (e.g. via javadoc).
Due to the reduced compatibility of Java, most likely checked / unverified will never change.
For more details and specific examples, perhaps take a look at the blog post I made some time ago: Getting rid of checked exceptions
However, I sometimes still work with checked exceptions for several reasons:
- The existing code base is large and uses checked exceptions. The refactoring efforts for excluded exceptions are too high given the benefits.
- Most team members believe that the checked exception is somewhat good, and we agreed on democracy at several conventions.
source share