36

What kinds of exceptions I should consider while working with Android Room. From my research I found out that there is only one exception that might occur.

Room Exceptions

That is also when you are having Single<T> as a return type and you have an empty return. Other than that I couldn't find any other possible scenario that might throw an exception.

Of course, there might be some exceptions if you have some logical incorrect implementations, like

  • Editing scheme, but not implementing Migration
  • Not implementing OnConflictStrategy while inserting
  • Running Room on Main Thread while not allowing it with allowMainThreadQueries()

I did some research and tried out almost all possible cases, mostly with RxJava return types and I saw one exception mentioned above and that's it.

Here is my tests that I run

I wanted to make sure that I have implementation for every possible scenario and not have some exception and unexpected crashes. I was thinking of occurrences of SQLite exceptions might happen, but I believe it's wrapped around Room and it will handle. (Not sure)

Can you give any other possible exceptions that might occur?

musooff
  • 6,412
  • 3
  • 36
  • 65
  • 2
    great question, came here asking the same thing... – jesses.co.tt Jun 18 '19 at 17:45
  • 3
    This is not well documented for some reason. But I know at least some SQLiteExceptions are thrown by Room. E.g., Room will throw an SQLiteConstraintException if a ForeignKey constraint is violated. – McMath Sep 07 '19 at 23:33
  • There is also an exception. That says Database is locked. It is cause if you try to access the database while it is perform any action or other thread is preforming some task. – Talha Shahid May 12 '22 at 11:46
  • If you use the Room Converter and if the converter is not up to date or not created in the right form then the exception can occur. – Stephan John Dec 07 '22 at 11:41

0 Answers0