Is it best practice to use PHP Throwable while dealing with MySql DB Transactions?

Viewed 50

I need some clarification on the use of Throwable in PHP while dealing with mysql transactions. Somewhere I read it is not a good practice to use Throwable everywhere we get errors since Throwable will Catch ALL errors.

So lets consider below code snippet

public function test()
{
    $db->beginTransaction();

    try {
        //Some code here
    } catch (Exception $e) {
        $db->rollBack();
        throw $e;
    }
    return $this;
}

Assuming that db is handling a lot of data and many methods are using this same method for db queries. Now situation is like if I get error(Suppose TypeError or any other) while doing any db transaction so catch won't be able to handle it since it is an error and transaction will not be able to rollback in that case.

In such situations, would it be best practice to use Throwable all things considered or not ?

0 Answers
Related