Recall & Review
beginner
What is the purpose of a
finally block in Java?The
finally block is used to execute important code such as cleanup actions, regardless of whether an exception was thrown or caught.Click to reveal answer
beginner
When does the code inside a
finally block run?It runs after the
try and catch blocks finish, no matter if an exception occurred or not.Click to reveal answer
intermediate
Can a
finally block run if there is a return statement in the try block?Yes, the
finally block still runs even if the try block has a return statement.Click to reveal answer
advanced
What happens if an exception is thrown inside a
finally block?If an exception occurs in the
finally block, it can override any exception thrown in the try or catch blocks.Click to reveal answer
beginner
Is a
finally block mandatory after a try block?No, a
finally block is optional. Every try block must be followed by at least one catch or finally block.Click to reveal answer
What is guaranteed by the
finally block in Java?✗ Incorrect
The
finally block always runs after the try and catch blocks, no matter what happens.If a
return statement is in the try block, what happens to the finally block?✗ Incorrect
Even with a return in try, the finally block runs before the method returns.
Can a finally block be used without a catch block?
✗ Incorrect
A try block can be followed by a finally block without a catch block.
What happens if an exception is thrown inside a finally block?
✗ Incorrect
An exception in finally overrides any exception from try or catch.
Which of these is NOT true about finally blocks?
✗ Incorrect
Finally blocks do not prevent exceptions; they run after try/catch but exceptions still propagate unless caught.
Explain the role of the finally block in Java exception handling.
Think about what code you want to run no matter what happens in try or catch.
You got /4 concepts.
Describe what happens when an exception is thrown inside a finally block.
Consider how exceptions in finally affect the original exception.
You got /3 concepts.