Home / Questions / What is the role of the finally clause in exception handling? Provide an example.
Explanatory Question

What is the role of the finally clause in exception handling? Provide an example.

👁 66 Views
📘 Detailed Answer
🕒 Easy to Read
Read the answer carefully and go through the related questions on the right side to improve your understanding of this topic.

Answer with Explanation

The finally clause contains code that runs regardless of how the try block exits. Example:


try
{
    // Code that might throw exceptions
}
catch
{
    // Handle exceptions
}
finally
{
    // Clean-up code
}