Bird
0
0

Identify the problem in this PHP code:

medium📝 Debug Q7 of 15
PHP - Error and Exception Handling

Identify the problem in this PHP code:

try {
  // code
} catch (Exception $e) {
  // handle
} catch (Error $e) {
  // handle error
} catch (Throwable $e) {
  // handle throwable
}
AVariable names must differ in catch blocks
BMissing try block braces
CMultiple catch blocks require 'or' keyword
DCatch blocks order causes unreachable code
Step-by-Step Solution
Solution:
  1. Step 1: Understand exception hierarchy

    Throwable is the base interface for Exception and Error.
  2. Step 2: Analyze catch order

    Exception and Error together cover all possible Throwables, making the final Throwable catch block unreachable.
  3. Final Answer:

    Catch blocks order causes unreachable code -> Option D
  4. Quick Check:

    Order catch blocks from specific to general [OK]
Quick Trick: Order catch blocks from specific to general exceptions [OK]
Common Mistakes:
  • Placing general catch blocks before specific ones
  • Using same variable name causes error
  • Using 'or' keyword between catch blocks

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes