Using System;
Using System. Collections. Generic;
Using System. Linq; using System. Text;
// 2014.3.14
Namespace _ 6. Exception
{
Class Program
{
Static void Main (string [] args)
{
Try
{
Console. WriteLine ("before Convert ");
Int a = Convert. ToInt32 (Console. ReadLine ());
Console. WriteLine ("after Convert ");
}
Catch (Exception ex)
{
Console. WriteLine ("input error:" + ex. Message + "exception Stack:" + ex. StackTrace );
}
Try
{
Console. WriteLine ("Enter your age :");
Int s = Convert. ToInt32 (Console. ReadLine ());
String desc = GetAgeDesc (s );
Console. WriteLine (desc );
}
Catch (Exception ex)
{
Console. WriteLine ("data error," + ex. Message );
}
Console. ReadKey ();
}
Static string GetAgeDesc (int age)
{
If (age> = 0 & age <= 3)
{
Return "infants ";
}
Else if (age> 3 & age <18)
{
Return "Teenagers ";
}
Else if (age> = 18 & age <60)
{
Return "adult ";
}
Else if (age> = 60 & age <100)
{
Return "Elderly ";
}
Else
{
Throw new Exception ("self-created ex. Message ");
}
}
}
}