View Single Post
  #1  
Old 17-06-2011, 09:54 PM
thecool's Avatar
thecool thecool is offline
Senior Member


 
Join Date: Apr 2009
Location: Multan
Posts: 1,163
Contact Number: Push me a PM if you really need
Program / Discipline: Alumni
Class Roll Number: ---
thecool has a reputation beyond reputethecool has a reputation beyond reputethecool has a reputation beyond reputethecool has a reputation beyond reputethecool has a reputation beyond reputethecool has a reputation beyond reputethecool has a reputation beyond reputethecool has a reputation beyond reputethecool has a reputation beyond reputethecool has a reputation beyond reputethecool has a reputation beyond repute
Read how to handle Index Out Of Range Exception in C Sharp

how to handle IndexOutOfRangeException in C Sharp
Code:
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();
}
}
}

Reply With Quote