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
- A
catch (Exception $e) - B
catch (MyException $e) - C
catch (MyException | TheirException $e) - D
catch (Error $e)
How the community answered
(36 responses)- A11% (4)
- B3% (1)
- C81% (29)
- D6% (2)
Topics
#exception hierarchy#catch blocks#custom exceptions#union catch
Community Discussion
No community discussion yet for this question.