Android SQLiteOpenHelper:确定 onUpgrade 异常的原因
Android SQLiteOpenHelper: Determining reason for onUpgrade exceptions
我想记录在我的应用程序的 SQLiteOpenHelper 的 onUpgrade 方法上可能发生的任何异常,以便我可以在后续更新中修复任何查询问题。
关于异常,文档只提到了以下内容:
This method executes within a transaction. If an exception is thrown,
all changes will automatically be rolled back.
有谁知道我可以如何确定我的 Android 应用中的 onUpgrade 方法失败的原因?
您可以将 onUpgrade()
包装在 try
-catch
中,记录并重新抛出异常。沿着:
try {
db.execSQL(/* upgrades */);
} catch (Throwable t) {
Log.w(TAG, "onUpgrade failed", t);
throw t;
}
我想记录在我的应用程序的 SQLiteOpenHelper 的 onUpgrade 方法上可能发生的任何异常,以便我可以在后续更新中修复任何查询问题。
关于异常,文档只提到了以下内容:
This method executes within a transaction. If an exception is thrown, all changes will automatically be rolled back.
有谁知道我可以如何确定我的 Android 应用中的 onUpgrade 方法失败的原因?
您可以将 onUpgrade()
包装在 try
-catch
中,记录并重新抛出异常。沿着:
try {
db.execSQL(/* upgrades */);
} catch (Throwable t) {
Log.w(TAG, "onUpgrade failed", t);
throw t;
}