Catch different exceptions

image_pdfimage_print
   

/*
C# Programming Tips & Techniques
by Charles Wright, Kris Jamsa

Publisher: Osborne/McGraw-Hill (December 28, 2001)
ISBN: 0072193794
*/

namespace nsCompare
{
    using System;
    public class Compare
    {
        static public void Main (string [] args)
        {
            int TestArg;
            try
            {
                TestArg = int.Parse (args[0]);
            }
            catch (FormatException)
            {
                Console.WriteLine ("Please enter a number value.");
                return;
            }
            catch (IndexOutOfRangeException)
            {
                Console.WriteLine ("Please enter an argument");
                return;
            }
            string str;
            str = TestArg > 10 ? "The test is true" : "The test is false";
            Console.WriteLine (str);
        }
    }
}