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


Please Help Members By Posting Answers For Below Questions

Why interface is required?

626


What is the difference between field and property in c#?

688


Explain types of comment in c# with examples

687


Where is the main method in c#?

729


what is c# command?

704


What is public, private, protected, internal and internal protected?

710


Explain boxing and unboxing in c#?

693


What is the object class in c#?

694


What is difference between string and string builder?

706


How do you convert byte array to hexadecimal string, and vice versa?

768


How we can create an array with non-default values?

718


What are the types of parameters in c#?

716


Why do I get a "cs5001: does not have an entry point defined" error when compiling?

748


how to insert the data from the grid view to database table though button click.pls send the answer to mail id suri1319@gmail.com

1703


What is the difference between throw and throw ex?

653