使用 sqlite insertOrThrow 的正确方法

Proper way of using sqlite insertOrThrow

我的代码看起来像这样:

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

一切正常,但不幸的是,插入查询在我的用户设备上总是 return -1。我的应用程序有错误,所以现在我更改了

insert

database.insertOrThrow

希望当用户的 phone 再次出现错误时,bugsnag 会通知我。但只是为了确保(因为我以前从未使用过 insertOrThrow;通常只是插入封装在 try catch 中),上面的代码是否足够?当 insert 发生错误时,bugsnag 会捕获它吗?也许我的问题可以概括为'how do I handle throw in insertOrThrow?'

insertOrThrow在出错时抛出一个SQLException,它是RuntimeException的子类。

Bugsnag 将通过注册 Thread.UncaughtExceptionHandler 自动处理您的应用程序中任何未捕获的异常,因此您不需要执行任何其他操作来捕获事件。

请确保您在创建 table 时声明的所有值都用于解决问题。