In a try-catch block, what is the role of the 'finally' clause?

  • Declares a variable to store exception details
  • Defines a custom exception message
  • Executes code regardless of whether an exception is thrown or not
  • Specifies the code to be executed if an exception is thrown
The 'finally' clause is used to specify a block of code that will be executed regardless of whether an exception is thrown or not. This is useful for tasks such as releasing resources or closing connections, ensuring cleanup operations are performed.
Add your answer
Loading...

Leave a comment

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