Bird
0
0

In PHP, when is the finally block executed in a try-catch-finally structure?

easy📝 Conceptual Q1 of 15
PHP - Error and Exception Handling
In PHP, when is the finally block executed in a try-catch-finally structure?
AAlways, regardless of whether an exception is thrown or caught
BOnly if an exception is thrown
COnly if no exception is thrown
DOnly if the catch block is executed
Step-by-Step Solution
Solution:
  1. Step 1: Understand the role of finally block

    The finally block is designed to run code that must execute no matter what happens in the try or catch blocks.
  2. Step 2: Analyze execution flow

    Whether an exception occurs or not, and whether it is caught or not, the finally block always runs.
  3. Final Answer:

    Always, regardless of whether an exception is thrown or caught -> Option A
  4. Quick Check:

    finally block execution = always [OK]
Quick Trick: finally block always runs after try/catch [OK]
Common Mistakes:
  • Thinking finally runs only on exceptions
  • Assuming finally runs only if catch executes
  • Believing finally can be skipped

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PHP Quizzes