Recall & Review
beginner
What is the purpose of the
finally block in PHP?The
finally block contains code that always runs after try and catch blocks, regardless of whether an exception was thrown or caught.Click to reveal answer
beginner
When does the code inside a
finally block execute?It executes after the
try block finishes, whether or not an exception was thrown or caught, and even if there is a return statement inside try or catch.Click to reveal answer
intermediate
Can the
finally block override a return statement in the try or catch blocks?Yes, if the
finally block contains a return statement, it will override any previous return from try or catch.Click to reveal answer
advanced
What happens if an exception is thrown inside the
finally block?If an exception is thrown inside
finally, it will override any exception thrown in the try or catch blocks and propagate up the call stack.Click to reveal answer
beginner
Is the
finally block mandatory in PHP exception handling?No, the
finally block is optional. You can use try with catch alone, but finally is useful for cleanup code that must always run.Click to reveal answer
When does the
finally block run in PHP?✗ Incorrect
The
finally block always runs after try and catch, regardless of exceptions or returns.What happens if
finally contains a return statement?✗ Incorrect
A
return in finally overrides any earlier return from try or catch.If an exception is thrown in
finally, what happens?✗ Incorrect
An exception in
finally overrides any previous exception and propagates up.Is the
finally block required in PHP exception handling?✗ Incorrect
finally is optional and used for cleanup code.Which of these is a good use for
finally?✗ Incorrect
finally is ideal for cleanup tasks like closing files or connections.Explain how the
finally block behaves in PHP exception handling.Think about what happens no matter what in a try-catch-finally.
You got /5 concepts.
Describe what happens if there is a return statement in both the
try block and the finally block.Consider which return value the function actually sends back.
You got /3 concepts.