BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan

BZU PAGES: Find Presentations, Reports, Student's Assignments and Daily Discussion; Bahauddin Zakariya University Multan (http://bzupages.com/)
-   Visual Programming (http://bzupages.com/73-visual-programming/)
-   -   how to handle Index Out Of Range Exception in C Sharp (http://bzupages.com/f73/how-handle-index-out-range-exception-c-sharp-16479/)

thecool 17-06-2011 09:54 PM

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();
}
}
}



All times are GMT +5. The time now is 06:11 PM.

Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.