imin
imin

Reputation: 4578

Proper way of using 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's device. My app has bugsnag so now I changed the

insert

to

database.insertOrThrow

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

Upvotes: 4

Views: 579

Answers (2)

blackbot
blackbot

Reputation: 1

Make sure you are putting all the values that you have been declared during creating the table in my case that solve the problem.

Upvotes: 0

fractalwrench
fractalwrench

Reputation: 4076

insertOrThrow throws a SQLException in the event of an error, which is a subclass of RuntimeException.

Bugsnag will automatically handle any uncaught exceptions in your app by registering a Thread.UncaughtExceptionHandler, so you shouldn't need to do anything else to capture the event.

Upvotes: 2

Related Questions