exception handling c#
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();
}
}
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: