This is my syntax so far:
static void Main(string[] args)
{
// create a writer and open the file
System.IO.StreamReader reader =
new System.IO.StreamReader("c:\\Numbers.txt"); ;
// open file in Output
using (System.IO.StreamWriter file = new System.IO.StreamWriter(@"C:\Output.txt"))
{
string line;
int Count = 1;
while ((line = reader.ReadLine()) != null)
{
int y = Int32.Parse(line);
if ((y % 2) == 0)
{
file.WriteLine(" Number " + y + " in line " + Count + " is even ");
}
else
{
file.WriteLine(" Number " + y + " in line " + Count + " is odd ");
}
Count++;
}
file.Close();
reader.Close();
}
}
I need to invoke exceptions that would output the following lines:
FormatException - Input string was not in a correct format., line No.=10, String=ABC
OverflowException - Value was either too large or too small for an Int32., line No.=11, String=123456789012345678901234567890
FormatException - Input string was not in a correct format., line No.=14, String=4.0
Could anyone help on where and how to write these exceptions.