Bird
0
0

Why does PHP require thrown objects to implement the Throwable interface?

hard📝 Conceptual Q10 of 15
PHP - Error and Exception Handling
Why does PHP require thrown objects to implement the Throwable interface?
ATo restrict exceptions to only built-in classes.
BTo ensure all exceptions have common methods like getMessage().
CTo allow throwing any object regardless of type.
DTo automatically log all exceptions.
Step-by-Step Solution
Solution:
  1. Step 1: Understand purpose of Throwable interface

    The Throwable interface defines common methods like getMessage() that all exceptions must have.
  2. Step 2: Evaluate other options

    PHP does not allow throwing any object, nor restricts to built-in classes only, nor automatically logs exceptions.
  3. Final Answer:

    To ensure all exceptions have common methods like getMessage(). -> Option B
  4. Quick Check:

    Throwable interface defines common exception methods [OK]
Quick Trick: Throwable ensures exceptions share common methods [OK]
Common Mistakes:
  • Thinking any object can be thrown
  • Assuming Throwable restricts to built-in classes
  • Believing Throwable auto-logs exceptions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes