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

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

}

平地机班(单身班)

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

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

     return $this;
 }

 public function handleError($message)
 {

 }

我如何编写handleError函数以使其停止当前执行,这意味着永远不会到达validateHandler函数中的return $this,将错误消息打印到屏幕上,但是for循环不会停止运行?

4

1 回答 1

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');
}
于 2012-06-28T12:08:25.860 回答