how to handle exceptions when using Room with LiveData

Viewed 209

when using android-room with LiveData together, it sometimes throw Exeptions such as SQLiteCantOpenDatabaseException & SQLiteFullException, but I can't find a chance to catch the excpetions as the LiveData object was generated automaticlly by Room. how can i handle exceptions when using Room with LiveData?

below is my dao:

@Dao
public interface Dao {

    @Insert(onConflict = IGNORE)
    long add(TraceEntity host);

    @Query("select * from trace where _id = :id")
    Entity findById(long id);

    @Delete
    int del(Entity host);

    @Query("select * from trace")
    LiveData<List<Entity>> queryAll();

    @Query("SELECT COUNT(_id) FROM trace")
    LiveData<Integer> getCount();
}
0 Answers
Related