Sponsored Ad

Friday, December 17, 2010

How to Execute Next Statement After Error in C#

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.

How to Execute Next Statement After Error in C#

Code to Bypass Error and Execute Next Statement:

using System;

namespace MyApp
{
    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();
        }    
    }
}

No comments:

Post a Comment

Sponsored Ad

Development Updates