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

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

}

Grader Class (Singleton class)

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

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

     return $this;
 }

 public function handleError($message)
 {

 }

How to i write the handleError function such that it stops the current execution meaning return $this in the validateHandler function is never reached, prints an error message to the screen, the for loop however does not stop running?

1 Answer 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');
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.