Bird
0
0

Which class must an object belong to in order to be thrown as an exception in PHP?

easy📝 Conceptual Q2 of 15
PHP - Error and Exception Handling
Which class must an object belong to in order to be thrown as an exception in PHP?
AAny class that extends the built-in Exception class.
BOnly the base Exception class itself.
CAny class that implements the Throwable interface.
DAny class that extends the Error class.
Step-by-Step Solution
Solution:
  1. Step 1: Identify PHP exception requirements

    PHP requires thrown objects to implement the Throwable interface, which both Exception and Error classes implement.
  2. Step 2: Evaluate options

    Extending Exception is common but not the only way. Implementing Throwable is the requirement. Extending Error is allowed but not the only way.
  3. Final Answer:

    Any class that implements the Throwable interface. -> Option C
  4. Quick Check:

    Thrown object = implements Throwable [OK]
Quick Trick: Thrown exceptions must implement Throwable interface [OK]
Common Mistakes:
  • Thinking only Exception class can be thrown
  • Confusing Error and Exception classes
  • Ignoring the Throwable interface requirement

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes