首页 > 代码库 > try throw catch 多个throw 捕获的问题

try throw catch 多个throw 捕获的问题

当有多个throw语句时,catch捕获的是第一个throw语句

<?php $a=1;

      try{  if($a!=2){   throw new Exception(‘not equal 2.‘);}    

                $a=b;       

              if($a!=3){   throw new Exception(‘not equal 3.‘);}   

                $a=c;

} catch (Exception $e){  

          echo $e->getMessage();  

          echo "<br>";  

          echo $a;  

          echo "<br>"; }

          echo $a;

?>