Hello, all.
Seeing a checked expection in API is not rare, one of the most well known examples is IOException
in Closeable.close()
. And often dealing with this exception really annoys me. Even more annoying example was in one of our projects. It consists from several components and each component declares specific checked exception. The problem (in my opinion) is that at design time it was not exactly known what certain exceptions would be. Thus, for instance, component Configurator
declared ConfiguratorExeption
. When I asked why not just use unchecked exceptions, I was told that we want our app to be robust and not to blow in runtime. But it seams to be a weak argument because:
- Most of those exceptions effectively make app unusable. Yes, it doesn't blow up, but it cannot make anything exepting flooding log with messages.
- Those exceptions are not specific and virtually mean that 'something bad happened'. How client is supposed to recover?
- In fact all recovering consists from logging exception and then swallowing it. This is performed in large
try-catch
statement.
I think, that this is a recurring pattern. But still checked exceptions are widely used in APIs. What is the reason for this? Are there certain types of APIs that are more appropriate for checked exceptions?