Examples of exception handling in c#

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

namespace excep_sys

{

class Program

{
static void Main(string[] args)
{
int a;
Console.WriteLine("Enter some number:");
try
{
a=int.Parse (Console.ReadLine());
if(a>=0&&a<=5)
{
Console.WriteLine ("Entered number is: "+a);
}
else
{
throw new IndexOutOfRangeException();
}
}

catch(IndexOutOfRangeException ex)

{
Console.WriteLine ("Number is not between 0 to 5"+ex.Message );
}

Console.ReadLine();



}

}
}

0 comments:

Post a Comment