nerdexam
Zend

200-710 · Question #230

Given the following PHP code: ``php <?php class MyException extends Exception { // } try { throw new MyException('something went wrong'); } { echo $e->getMessage(); } ?> `` Which code, if put on…

The correct answer is C. `catch (MyException | TheirException $e)`. See the full explanation below for the reasoning.

Error Handling

Question

Given the following PHP code:
<?php
class MyException extends Exception {
 //
}

try {
 throw new MyException('something went wrong');
} *** {
 echo $e->getMessage();
}
?>
Which code, if put on place of '***', will NOT prompt the code to output "something went wrong" when run?

Options

  • Acatch (Exception $e)
  • Bcatch (MyException $e)
  • Ccatch (MyException | TheirException $e)
  • Dcatch (Error $e)

How the community answered

(36 responses)
  • A
    11% (4)
  • B
    3% (1)
  • C
    81% (29)
  • D
    6% (2)

Topics

#exception hierarchy#catch blocks#custom exceptions#union catch

Community Discussion

No community discussion yet for this question.

Full 200-710 Practice