Answer: Yes, the finally block executes even if the exception is unhandled
Consider this code snippet
using System;
class abc
{
static void Main()
{
try
{
Console.WriteLine("enter");
int a=Convert.ToInt32(Console.ReadLine());
Console.WriteLine("hello"+"---"+a);
}
finally
{
Console.WriteLine("good");
}
}
}
Compile it and run from the Visual sTUDIO Command prompt
put some error value (Example: abc)
The output will consist of the error message and the
good string in the
finally block will be displayed.
Asked In: Many Interviews |
Alert Moderator