Reputation: 2663
i have created one android application that was connecting to sqlite database.
and i have given a unique constraint
for multiple fields exactly 2 fields say username and password.
am expecting the app will thrown exception while am trying to insert the duplicate entry.
and in the Logcat am getting the following exception :
01-04 16:52:06.604: E/SQLiteDatabase(1432): android.database.sqlite.SQLiteConstraintException: error code 19: constraint failed
in the line am trying to insert db.insert(userTable, null, cv);
but even if am writing this code in a try..catch
block the control is not entered into my catch
block.
Experts please tell why this case happends.?
Thanks in advance.
Upvotes: 3
Views: 1739
Reputation: 1909
you can try this:
try{
db.insertOrThrow(userTable, null, cv);
} catch (android.database.sqlite.SQLiteConstraintException ex) {
}
Upvotes: 0
Reputation: 68187
use as below:
try{
db.insertOrThrow(userTable, null, cv);
}
catch(SQLiteConstraintException ex){
//what ever you want to do
}
Upvotes: 2