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/index.php)
-   Visual Programming (http://bzupages.com/forumdisplay.php?f=73)
-   -   how to handle Index Out Of Range Exception in C Sharp (http://bzupages.com/showthread.php?t=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 11:23 PM.

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