How to efficiently use try…catch blocks in PHP

前端 未结 8 1657
自闭症患者
自闭症患者 2020-12-02 05:31

I have been using try..catch blocks in my PHP code, but I\'m not sure if I\'ve been using them correctly.

For example, some of my code looks like:

 t         


        
8条回答
  •  爱一瞬间的悲伤
    2020-12-02 06:11

    It's more readable a single try catch block. If its important identify a kind of error I recommend customize your Exceptions.

    try {
      $tableAresults = $dbHandler->doSomethingWithTableA();
      $tableBresults = $dbHandler->doSomethingElseWithTableB();
    } catch (TableAException $e){
      throw $e;
    } catch (Exception $e) {
      throw $e;
    }
    

提交回复
热议问题