How to Execute Next Statement After Error in C#

Shubham
Posted by Shubham under C# category on | Points: 40 | Views : 1295
This Code will help to to bypass error and execute all other statements. For example in this scenario we have two statements. one is before error and another is after error. In normal case if any error occurs the control will not execute the next statements after errors. While if we use the try catch block and suppress the error then it will execute the next statements also.

You can also handle the error in exception block as per your requirement.....


using System;

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Satement Before Error.");
try
{
int i = Convert.ToInt16("Str");
}
catch (Exception ex)
{
}
Console.WriteLine("Satement After Error.");
Console.ReadLine();
}
}
this question will help you on interview..........

Comments or Responses

Login to post response