I was using try..catch blocks in my PHP code for some time now but I don't know if the way I was using it is correct.
For example:
try {
$tableAresults = $dbHandler->doSomethingWithTableA();
$tableBresults = $dbHandler->doSomethingElseWithTableB();
} catch (Exception $e) {
return $e;
}
I think this above method is better than this:
try {
$tableAresults = $dbHandler->doSomethingWithTableA();
} catch (Exception $e) {
return $e;
}
try {
$tableBresults = $dbHandler->doSomethingWithTableB();
} catch (Exception $e) {
return $e;
}
I did the first code so as to group multiple database operations in the same try/catch block. Is this a good practice? Is there any advantage of using try/catch blocks per database transaction?