Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

about transaction rollback

Do I need to throw an exception after transation rollback in try catch block? Thx



81.8k

That depends on the type of strategy you are using to handle the transactions.



14.4k

the code is something like:

try {
   ...
   $a->setTransaction($t);
   $b->setTransaction($t);

   if (!$a->save()) {
      $t->rollback();
      /*
      Do I need add return or throw new Exception(); here to exit current follow and goto finally block?
      */
   }

   if (!$b->save()) {
      $t->rollback();
      /*And here*/
   }
   $t->commit();
}
catch (Exception $e) {
   ...
}
finally {
   ...
}


81.8k
Accepted
answer

Yes, you need to throw an exception after $t->rollback();