Exceptions · interview question
Which statements about finally are true? Select all that apply.
Select all that applyMedium
Answer and explanation
Correct answer
- A. It runs whether or not an exception is thrown in the try block.
- B. A
returninsidefinallyoverrides areturnin the try block. - D. A try block can have a finally block without any catch block.
Why
Avoid return and throw in finally; both can silently discard the original exception.
References
Test yourself on Exceptions
A free test with instant, explained results. No account needed.
More Exceptions questions
- Why does chaining exceptions in Java help in practice?
- Why can overusing exception wrapping become a problem in practice?
- Why wrap an exception with the original cause instead of replacing it completely?
- Which of the following is NOT a recommended practice for exception handling?
- Which method is used to retrieve the original cause of a chained exception?
- What exception type should you throw when encountering a database connection error in an e-commerce application?