Tuesday, July 8, 2014

Exception handling in c#

using System;
class excep
{
public static void Main()
{
int a;
try
{
Console.Write("Enter the value for a:");
a=Convert.ToInt32(Console.ReadLine());
if(a==5)
throw new myexp();
else
Console.WriteLine("a value is not 5");
Console.WriteLine("This lines will b skipped if throw is executed");
 }
catch(myexp e)
{
Console.WriteLine("A value is 5 "+e.msg());
}
finally
{
Console.WriteLine("This stmt ll execute finally after catch or after try block");
}
}
}
class myexp:Exception
{
public string msg()
{
return "Vadivelan";
}
}

No comments:

Post a Comment