2012-06-28 111 views
4
foreach ($scripts as $script) {  
    $grader = Grader::getInstance(); 

    $grader->setApplicantId($script['applicant_id']) 
     ->setHandler($x) 
     ->doGrading(); 

} 

平地機類(Singleton類)PHP - 錯誤處理

public function setHandler($x) 
{ 
    $this->validateHandler($x); 
} 

public function validateHandler($x) 
{ 
    $this->handleError("Invalid Handler"); 

    return $this; 
} 

public function handleError($message) 
{ 

} 

如何我寫的HandleError功能,使得它停止當前的執行意味着這在validateHandler函數返回$從未達到,版畫屏幕出現錯誤信息,for循環卻不停止運行?

回答

3
foreach ($scripts as $script) {  
    try { 
     $grader = Grader::getInstance(); 

     $grader->setApplicantId($script['applicant_id']) 
      ->setHandler($x) 
      ->doGrading(); 
    } 
    catch ($e) { 
     echo 'Grading failed for applicant '.$script['applicant_id']; 
    } 
} 

... 

public function handleError($message) 
{ 
    throw new Exception('Unable to fruzz the bubar'); 
} 
+0

非常感謝你.....它的偉大工程 – kayfun