Alex T Alex T - 3 months ago 18
ASP.NET (C#) Question

Difference between code cleanup in finally block and after catch block (C#)

What is the difference between adding cleanup code in finally block and cleanup code after the catch block ?

try
{
//some code
}
catch
{
}
finally
{
//cleanup
}


and

try
{
//some code
}
catch
{
}
//cleanup

h22 h22
Answer

If you throw a throwable from the try .. catch block that is not caught by this catch, the cleanup code inside the finally clause will execute and the code immediately after the catch block will not.