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


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


the code is something like:

try {

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

   if (!$b->save()) {
      /*And here*/
catch (Exception $e) {
finally {


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

According to the docs if you use TransactionManager you can catch Phalcon\Mvc\Model\Transaction\Failed $e exception:


try {
   use Phalcon\Mvc\Model\Transaction\Manager as TransactionManager;

   $transactionManager = new TransactionManager();

   $transaction = $transactionManager->get();

   $robot = new Robots();


   $robot->name       = "WALL·E";
   $robot->created_at = date("Y-m-d");

   if ($robot->save() === false){
       $transaction->rollback("Can't save robot");

   $robotPart = new RobotParts();


   $robotPart->type = "head";

   if ($robotPart->save() === false) {
       $transaction->rollback("Can't save robot part");

} catch (Phalcon\Mvc\Model\Transaction\Failed $e) {
   echo "Failed, reason: ", $e->getMessage();