tags:

views:

111

answers:

1

Here is the standard idiom for transactions:

   db.beginTransaction();
   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?

+2  A: 

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.

CommonsWare
What if your own code gets an exception? Then half of what you intended to do will be committed. Is there an explicit rollback?
Stroboskop
"What if your own code gets an exception?" -- that is what is indicated by the `...` in the above code snippet. "Then half of what you intended to do will be committed." -- no, it won't. "Is there an explicit rollback?" -- no, and you don't need one.
CommonsWare
Oh, i didn't see the `db.setTransactionSuccessful();`
Stroboskop