C#

Drop Down MenusCSS Drop Down MenuPure CSS Dropdown Menu

Sunday, 10 November 2013

multiple try catch


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

namespace multiple_trycatch
{
    class Program
    {
        public static void Main(string[] args)
        {

            int x = 0;
            int div=0;

            try
            {
                div = 100 / x;
             

            }
            catch (DivideByZeroException ex)
            {
                Console.WriteLine("I said you divide the number with a positive number other than zero man");
                Console.WriteLine("divide by zero exception");
                Console.WriteLine("lets see what message we are getting= {0}", ex.Message);

            }

            catch (Exception allotherexception)
            {
                Console.WriteLine("I will work if other fails");
           
            }

            finally
             {
             Console.WriteLine("got it man....");  
           
             }

            Console.WriteLine("so the output of the divison is {0}", div);
            Console.ReadLine();
       
        }


    }
}
/*
 so this is quite simple.......
 * look at these two lines here lies one concept
 *
   int div=0;
 *  Console.WriteLine("so the output of the divison is {0}", div);
 *
 * you gotta initialise the div =0.....
 *
 * otherwise you get error like
 "use of unassigned local variable 'div'"
  catch (Exception allotherexception)
            {
                Console.WriteLine("I will work if other fails");
           
            }
i hope you got the above lines......freeze the other catch and try this catch...
 * this will work..........
 *

 */

No comments:

Post a Comment