Bird
0
0

Find the problem in this PHP code:

medium📝 Debug Q7 of 15
PHP - Error and Exception Handling
Find the problem in this PHP code:
try {
  echo "Start";
  throw new Exception("Oops");
} catch (Exception $e) {
  echo "Caught";
} finally {
  return;
  echo "Done";
}
AException is not caught properly
BReturn cannot be used inside finally
CNo problem, code runs fine
DCode after return in finally is unreachable
Step-by-Step Solution
Solution:
  1. Step 1: Analyze finally block

    Return statement ends function execution immediately.
  2. Step 2: Check code after return

    Code after return (echo "Done") is unreachable and will never run.
  3. Final Answer:

    Code after return in finally is unreachable -> Option D
  4. Quick Check:

    Code after return is unreachable [OK]
Quick Trick: No code runs after return in finally [OK]
Common Mistakes:
  • Thinking return is disallowed in finally
  • Expecting code after return to run
  • Ignoring unreachable code warnings

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes