Which of the following is true regarding the flow of control in a try-catch-finally statement?

  • The catch block is executed before finally.
  • The catch block is optional.
  • The code inside try is optional.
  • The finally block is executed before try.
In a try-catch-finally statement in Java, the flow of control is such that the try block is executed first. If an exception occurs within the try block, control is transferred to the appropriate catch block (if matching). Finally block is executed after try (whether an exception occurred or not), making it suitable for cleanup code.
Add your answer
Loading...

Leave a comment

Your email address will not be published. Required fields are marked *