java - Is using checked exceptions in external APIs a good idea? -
A test extraction is not rare in the API, one of the most famous examples is IOException
In and often annoys me to deal with this exception really annoying example was one of our projects. It is composed of many components and each component declares specific check exceptions. The problem (in my opinion) is that at design time it was not known exactly what would be the exception. Thus, for example, component configurator
declared configurator access
. When I asked why not only use uncontrolled exceptions, I was told that we want our app to be strong and do not shock in runtime. But it can be as fast as a weak argument because:
- Most of those exceptions make the app unusable, yes, it does not blow up, but these messages Can not do anything to open flood logs.
- Those exceptions are not specific, and in effect it means that 'something bad happened' how is it supposed to fix the client?
- In fact, there are exceptions for logging in all the recovery and then it is swallowed in this large
try-catch
statement.
I think, this is a recurring pattern. But the still checked exceptions are widely used in the APIs. What is the reason for this? Are there some special types of APIs that are more suitable for exceptions to the investigation?
There are so many issues this issue.
Take a look at this classic article about that topic
I am personally in favor of using the runtime
exceptions and I think The exception to checking in your API is a bad idea.
In fact, some very popular Java APIs have started to do this, for example, Hibernate used exceptions for the investigation to leave version 3 to runtime For, the use of the Spring framework runtime is also favorable for the exceptions being examined.
Comments
Post a Comment