how to create own exception in c sharp
how to create a exceptionn
friends today i will tell how to create own exception .
using System;
namespace rahul
{
class ownexception
{
static void Main(string[]args)
{
firstexception fs=new firstexception();
try
{
fs.dowork();
}
catch(Myexception e)
{
Console.WriteLine("exception handle {0}",e.message);
}
Console.ReadLine();
firstexception fs=new firstexception();
try
{
fs.dowork();
}
catch(Myexception e)
{
Console.WriteLine("exception handle {0}",e.message);
}
Console.ReadLine();
}
}
}
public class Myexception:applicationException
{
public Myexception(string message):base (message)
{
}
}
public class firstexception
{
int sum=0;
int count=0;
float average;
public void dowork()
{
if(count==0)
if(count==0)
{
throw(new Myexception("zero count in dowork"));
}
else
averge=sum/count;
}
}
No comments: