Here is the standard idiom for transactions:
db.beginTransact开发者_开发百科ion();
try {
...
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
I want to add a catch block, and I want to issue a rollback. Is it possible, and at all do I need it?
You do not need it.
If there is an exception in the ...
in your above code, the code you already have will roll back the transaction. The finally {}
block is executed after the catch() {}
block.
精彩评论