2011-04-26 60 views
2

我试图捕获错误腓catch异常

 try  
     { 
      $outcome   = $bet->getElementsByTagName("Outcome"); 
      $line1    = $outcome->item(0)->getElementsByTagName("OptionalValue1")->item(0)->nodeValue;      
      $line2    = $outcome->item(2)->getElementsByTagName("OptionalValue1")->item(0)->nodeValue; 
      $aOdds["line"]  = ($line1 == 0) ? -$line2 : $line1; 

      $aOdds["q1"]  = $outcome->item(0)->getAttribute("odds"); 
      $aOdds["qx"]  = $outcome->item(1)->getAttribute("odds"); 
      $aOdds["q2"]  = $outcome->item(2)->getAttribute("odds"); 
     } 
     catch (Exception $e) 
     { 
      $outcome   = $bet->getElementsByTagName("Outcome"); 
      $line1    = $outcome->item(0)->getElementsByTagName("OptionalValue1")->item(0)->nodeValue;      
      $line2    = $outcome->item(1)->getElementsByTagName("OptionalValue1")->item(0)->nodeValue; 
      $aOdds["line"]  = ($line1 == 0) ? -$line2 : $line1; 

      $aOdds["q1"]  = $outcome->item(0)->getAttribute("odds"); 
      $aOdds["qx"]  = 0; 
      $aOdds["q2"]  = $outcome->item(1)->getAttribute("odds"); 
     } 

一些数据配备了2相同的标记,并与3人,我想赶上如果不存在3.标签,但错误捕捉不到真正的工作。

+1

你能不能细说 “没有真正的工作?” – 2011-04-26 19:16:09

+0

某些事情必须真正抛出异常,才能够抓住它。 – 2011-04-26 19:35:18

+0

啊,我明白了:) – 2011-04-26 19:44:21

回答

1

你可以抛出自己的异常在try块

if (some condition) { 
    throw new Exception("Error message"); 
} 
0

你肯定的是,在try块码,错误将抛出一个异常? 的尝试statment是能够赶上这是由这个PHP代码抛出异常:

throw new Exception('exception raised'); 

请看看here,在注释窗格。