1. <?php  
  2. try{  
  3.     $x=0;  
  4.     if($x==0)  
  5.         throw new Exception("不能被0除");  
  6.     $a=3/$x;  
  7.     echo $a;  
  8. }catch(Exception $e){  
  9.     echo "error:".$e->getMessage();  
  10. }  
  11. ?> 

注意:首先需要throw new 抛出一个异常,然后再try catch