Why is the android.database.SQLException parameter not set?

This may not be suitable for SO, because it is not a coding problem, but so far I have not found a satisfactory answer, and I believe that the SO community can.

So, by definition, android.database.SQLException and java.sql.SQLException exchange the same scope, which is to provide information about errors when accessing / modifying a database. Although I read somewhere that checked exceptions "go out", I really like the fact that the compiler reminds you of exception handling when you use checked exceptions with the throws keyword. Unfortunately, this does not work with unchecked exceptions.

My question is: Why hasn't Google turned off android.database.SQLException when java.sql.SQLException marked? Am I missing something? They are different from each other, what do I think?

+4
source share
4 answers

The choice between excluding or excluding an exception is always somewhat subjective:

  • If the exception indicates an error or some kind of failure that is "possibly not being recovered," then an unchecked exception is thrown.

  • If the exception indicates an error that is likely to be recovered, then a valid exception is appropriate.

This is more difficult in cases where there is a general exception with a large number of subclasses. Some of these subclasses may be bugs, or they may be restored. At this point, the developer must evaluate the relative probability of the various cases ... in all known / predicted exception subtypes.

In this case, the engineers at Sun and Google came to different conclusions. But note that Google engineers had a big advantage that Sun engineers didn't have. They could take a look at the Java design and see for themselves how well it worked with the proven SQLException .


Although I read somewhere that checked exceptions are "out" ...

There are many developers who want all Java exceptions to be disabled so that they don’t have to force them to be eliminated. There are many other developers who still think that Java handled checked exceptions correctly ... although there were a few cases where the wrong choice was made (in retrospect).

This is debatable.

Am I missing something? They are different from each other, what do I think?

Not really. The two exception hierarchies serve pretty much the same purpose ... despite the differences in javadoc class descriptions.

+3
source

android.database.SQLException based on java.lang.RuntimeException and does not need to be checked, but java.sql.SQLException isn "t.

Unchecked Exceptions - The Controversy has a simple explanation.

+2
source

I think that Uncontrolled Exceptions prefer more proven Exceptions in many cases. The reason is that you are not forced to catch him. You can surround your code with a try-catch clause if you think it is necessary, but you do not have to. This effectively makes your code better, as the programmer can decide what to do.

In your example, there is no particular reason why you need to make it checked or not. This is a design issue in which I think Google handled android.database.SQLException better.

0
source

I think this is so because:

android.database.SQLException: An exception indicating an error while parsing or executing SQL.

and

java.sql.SQLException: exception that provides information about a database access error or other errors.

So, it is clear that android.database.SQLException is most likely a RuntimeException because it occurs when an error occurs with SQL parsing or execution. Whereas java.sql.SQLException is an exception due to a database access error or other similar errors, so it is large enough to save it as a checked exception. At any time when you work with open connections or any things of this type, it is better to have them under the umbrella of a checked exception.

0
source

All Articles