Correct way to use sqlite insertOrThrow

My code looks something like this:

ContentValues values = new ContentValues();
values.put("year", year);
values.put("month", month);
database.insert(MySQLiteHelper.TABLE_DATA, null, values);

      

Everything works fine, but unfortunately the insert query will always return -1 on one of my user devices. My app has bugsnag so now I changed

insert

to

database.insertOrThrow

hoping that when the error occurs again on the user's phone, bugsnag will notify me. BUT just to be sure (since I've never used insertOrThrow before, usually just insert encapsulated ones in try catch) is the above code enough? When an error occurs on insert, will errors be caught? Maybe my question can be summarized as "how do I handle throw in insertOrThrow?"

+3


source to share


1 answer


insertOrThrow

Throws SQLException on error that is subclassed RuntimeException

.



Bugsnag automatically handles any uncaught exceptions in your application by registering Thread.UncaughtExceptionHandler , so you don't need to do anything to catch the event.

+2


source







All Articles