Type of Exception:-
There are 2 type of exception
1)System Exception.
2)Application Exception.
System Exception:-
Exception that gets raised implictly of some predefind Condition is an “System Exception”.
Eg.DivideByZeroException,FormatException,OverFlowException,NullReference Exception
If u want to learn system Exception then read my article
Application Exception:-
Exception that gets raised explictly by the programmerin the application on own condition is an “Application Exception”.
It can also reffered as “User Defind Exception”
now lets we learn on how to develop own User Defind Exception.
When we develope User defind exception go to the following steps:
Step 1:
Inherited class form Exception class.
Eg. <Your class> : Exception
Step 2 :
Override the string message from exception class.
Eg.
Public override string Message
{
get
{
Return “Display the error Message when Exception Occour”
}
Step 3:-
In the another class, If exception is occour throws Exception for creation object of your own exception class
Eg.
Throws new <Own Exception name>
Lets start with demostration.
Demo:-
1) Open visual studio 2012.
2) Select file -> New ->Project
3) Select language as “visual c#” and template as “Console Application”,give appropritate name,I give name as UserDefindException.select Location as click on ok
4) Add new class by Right click on solution explore.add new Item choose class,give the name as NegativeNumberExceptionDemo.cs click on ok.
5) Write down the following code in the class.
6) Add new class “UserDefindDemo.cs” and click on add button
7) Write the following code in the class
Save it,debug the application check any error is occour ,if no any error then run the program,following output shown
Means when the result is negative then it is thrown exception and display the error message.
Which is created by user .
According to that way we can create own user defind exception.
Hope u enjoy my article.
If u like my artical hit the comment.
1 comments:
Click here for commentsNIce
ConversionConversion EmoticonEmoticon