© 2014 Firstsoft Technologies (P) Limited. login
Hi 'Guest'
Home SiteMap Contact Us Disclaimer
enggedu
Quick Links
Easy Studies

  HomeSource Code DotNet ► C# ▼

Try & Catch Block

Runtime errors occur at the time the program executes and can't be corrected. A programmer can, however, take preventive measures while coding the program, to handle runtime errors with the help of the try, catch, and finally keywords.

using System;
using System.Collections.Generic;
using System.Text;

namespace exception
{
    class Program
    {
        static void Main(string[] args)
        {
            int x = 1;
int intTemp = 0;
try
{
intTemp = 100/x;
Console.WriteLine("?Program terminated before this statement?");
}
catch(DivideByZeroException de)
{
Console.WriteLine("Division by Zero occurs");
Console.ReadLine();
}
finally
{
Console.WriteLine("Result is {0}", intTemp);
Console.ReadLine();
}
}

        }
    }

 

SLogix Student Projects
bottom