Friday, October 19, 2012

User defined exceptions in Asp.net using c#.Net

1.User define exception is a class,which must be inherited from exception class
2.It required based on the projects requirement
3.Syntax to write user defined exception class
class test:exception
{
}
4.User defined exception must be raised with throw keyword
syntax:throw new abc()

Here i will given an example to create user defined exception.I just placed a text box and button on the form

Class salexception:Exception
{
public salexception()
{
Messagebox.Show("sal must be 5K");
}
}//class sql exception
//code for button_click event
try
{
int sal =Int.Parse(txtsal.Text);
if(sal >5000)
Messagebox.Show("ur sal is:"+sal);
else
Throw new Exception ();
}
catch (salexception se)
{
}
}
Post a Comment

Bel