2011-04-26 3 views
2

캐치 예외PHP는 내가 오류를 잡으려고 노력하고있어

 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"); 
     } 

일부 데이터는이 같은 태그와 3 다른 사람과 함께 와서 내가 3. 태그가 존재하지 않을 경우 잡으려면,하지만 오류가 잡는 것은 정말로 효과가 없습니다.

+1

당신이에 정교한 수 없습니다 "정말 작동하지?" –

+0

뭔가 실제로 잡을 수있는 예외가 throw됩니다. –

+0

아, 알겠습니다. :) –

답변

1

당신은 try 블록에서 자신의 예외를 던질 수

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

당신은, try 블록의 코드에서 오류가 예외를 던질 것이라고 확신? 노트 창에서

throw new Exception('exception raised'); 

가보고 here을하시기 바랍니다 : 은 try의 한 Statment이 PHP 코드에 의해 던졌다되는 예외를 잡을 수있다.

관련 문제