Android: how should I handle database access exceptions?

My question is about good DB exception handling practices.

Let's say I have an application that stores some data in a database. The following levels exist:

  • DatabaseAdapter - processes SQL queries and provides data to a higher level in the form of a model. The adapter contains the following methods:
    • GetAllUsers () List
    • void addUser (user UserModel)
  • UserListActivity - displays a list of all users, allows you to add a new user, etc. This action uses the DatabaseAdapter to read / write the database.

Question: should I handle the database access exception, for example, when adding a new record (provided that the record must always be added correctly)? Should I just try to catch the exception in the DatabaseAdapter and add it to the log? Or maybe I shouldn't catch him?

+5
source share
2 answers

In most cases, an exception when querying the database is the result of a “design-time” error, such as a wrong request or change in your schema, but not an increase in the version of the database, or something similar. It will be quite easy to find and fix right on the spot, so your end users will not make these mistakes.

, :

  • SQLite ( ).
  • .
  • - , .
  • onUpgrade() - .
  • ( SQLite 3.6.19 ), .

, . , , , . :

, . RuntimeException , , - . , , , .

+4

, . . : ( SQL) , ( ​​ DB). , , DB, , CustomerNotFoundException, , .

0

All Articles