7/15/2010

C# Exception Handling (Nested Try)



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

namespace ExceptionHandling
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.WriteLine("Enter a value");
                int a = int.Parse(Console.ReadLine());

                try
                {
                    Console.WriteLine("Enter one more inetger value");
                    int b = int.Parse(Console.ReadLine());
                    Console.WriteLine("result: " + (a / b));
                }
                catch (FormatException e)
                {
                    Console.WriteLine(e.Message);
                }
            }

            catch (DivideByZeroException e)
            {
                Console.WriteLine(e.Message);
            }              

        }
    }
}

No comments:

Post a Comment