I have created a try block.Inside that try block again try block and it’s finally block.I closed that outside try block.followed by finally block.Suppose I don’t want to execute the finally block,for that I wrote Environment.Exit(0).Does there is any other method that stop finally block from execution.return 0;(that is in java).Please let me know.
public static int Main()
{
try
{
Console.WriteLine("First try block");
try
{
Console.WriteLine("Second try block");
//exit(0);
Environment.Exit(0);
//return 0;
}
finally
{
Console.WriteLine("Finally block of inner try");
}
}
finally
{
Console.WriteLine("Finally block of second try");
}
You can use Environment.FailFast() to exit the application immediately, while skipping finally and finalizers.
http://msdn.microsoft.com/en-us/library/ms131100.aspx