В чем проблема с этим кодом? Он не перехватывает исключение, генерируемое методом insertChild ()
.
childDbOps.open();
try {
childDbOps.insertChild(child);
} catch (SQLiteException exception) {
Log.i("error la inserare child", "on the next line");
exception.printStackTrace();
} finally {
childDbOps.close();
}
Ошибка:
ERROR/Database(320): android.database.sqlite.SQLiteConstraintException: error code 19:
constraint failed at com.android.dataLayer.DbAdapter.insertChild(DbAdapter.java:169)
at com.android.activities.ChildInsertActivity.onClick(ChildInsertActivity.java:203)
at android.view.View.performClick(View.java:2344)
Это Android-sqlite. Строка - это когда вызывается метод вставки.
Вы ловите только исключения типа SQLiteException
. Если метод insertChild
выдает любое другое исключение, он не будет пойман.
try {
childDbOps.insertChild(child);
}
catch(SQLiteException exception) {
Log.i("error la inserare child", "on the next line");
exception.printStackTrace();
}
catch(AnotherException exception) {
//handle it
}
//Catch them all here
catch(Exception exception) {
//handle it: must handle it, don't just swallow it.
}
finally {
childDbOps.close();
}
@bogdan есть ли другое место, где вы вызываете insertChild (child); кроме этого места. вы поместили трассировку в блок try, чтобы узнать, доходит ли она до этого блока, и распечатать трассировку, как показано ниже.
попробуйте {Log.i ("приходит здесь ");
childDbOps.insertChild (дочерний элемент); }
дайте мне знать.