If we write a goto or a return statement in try and catch
block will the finally block execute?
Answer Posted / uday
The statements after goto in try block wont be executed.
And Finally block also get executed.
static void Main(string[] args)
{
int a, b,c;
a = 10;
b = 0;
try
{
goto A;
c = a + b;
Console.WriteLine(c);
}
catch (Exception e)
{
Console.WriteLine("In parent exception Catch" +
e.Message);
}
finally
{
Console.WriteLine("In finally block");
}
A:
Console.WriteLine("at goto label");
Console.Read();
}
The output is:
In finally block
at goto label
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
How to parse a date time string?
What is the difference between integer and double?
Explain the difference between “system.array.clone()” and “system.array.copyto()” in c#?
Why do we need encapsulation in c#?
What is scope c#?
What's the difference between a static method and a non static method c#?
What are extension methods and where can we use them?
In which order the destructor is called for an inherited class?
What is entity framework c#?
What is difference between function and method in c#?
Why singleton class is sealed?
Why generics are used in c#?
Is java better than c sharp?
What are reflections in c#?
What is lock statement in C#?