Java – Why is android.database.SQLException unchecked?

Why is android.database.SQLException unchecked?… here is a solution to the problem.

Why is android.database.SQLException unchecked?

This may not be suitable for SO as it’s not really a coding problem, but I haven’t found a satisfactory answer yet and I believe the SO community can.

So, by definition< a href="http://developer.android.com/reference/android/database/SQLException.html" rel="noreferrer noopener nofollow">android.database.SQLException, and java.sql.SQLException Share the same scope of application, i.e. provide information about errors when accessing/modifying the database. While I’ve read somewhere that checking for exceptions is “out”, I really like the fact that when you use a check exception with the throws keyword, the compiler alerts you to handle the exception. Unfortunately, this does not apply to unchecked exceptions.

My question is:
Why didn’t Google select their android.database.SQLException when java.sql.SQLException was selected? Am I missing something? Are they more different than I thought?

Solution

The choice between checking for or not checking for anomalies is always somewhat subjective:

    If an exception

  • indicates an error or some “unrecoverable” failure, an unchecked exception is appropriate.

  • If the exception

  • indicates a “potentially recoverable” failure, it is appropriate to check for the exception.

In this case, the general anomaly with many subclasses is more difficult. Some of these subclasses may be buggy, or they may be recoverable. At this point, the designer must make a value judgment on the relative likelihood of different situations… All known/predicted subtypes that span the anomaly.

In this case, Sun and Google engineers came to different conclusions. Note, however, that Google engineers have a huge advantage that Sun engineers do not have. They can review the Java design and make their own judgments about how well it fits with the examined SQLException.


Though I’ve read somewhere that checked exceptions are “out” …

There are a lot of developers who want all Java exceptions to be unchecked so that they don’t have to be forced to deal with them. There are a lot of other developers who still think Java does a good job of checking for exceptions… Even in a few cases the wrong choice was made (in hindsight).

This is controversial.

Am I missing something? Do they differ more than I think?

Not really. The purpose of these two exception hierarchies is almost identical… Although there are differences in Javadoc class descriptions.

Related Problems and Solutions