Bird
0
0

What will this PHP code output?

medium📝 Predict Output Q5 of 15
PHP - Error and Exception Handling
What will this PHP code output?
try {
  echo 'Start';
  throw new Exception('Fail');
  echo 'End';
} catch (Exception $e) {
  echo 'Caught';
}
AStartEndCaught
BStartCaught
CCaught
DStartEnd
Step-by-Step Solution
Solution:
  1. Step 1: Trace the code execution

    'Start' is printed, then Exception is thrown, so 'End' is skipped.
  2. Step 2: Catch block runs after exception

    The catch block prints 'Caught'.
  3. Final Answer:

    StartCaught -> Option B
  4. Quick Check:

    Exception stops code, catch prints = StartCaught [OK]
Quick Trick: Code after throw is skipped; catch runs next [OK]
Common Mistakes:
  • Expecting 'End' to print after throw
  • Ignoring catch block output
  • Assuming no output after exception

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes