Exception
And
Exception Handling
Exception
Exception are typically regarded
as runtime anomalies.
Exceptions are often generated by
the CLR That identify the problem at
Hand.
Why Exceptions Occurred ????
Reasons Behind Exceptions.
Attempting to connect to a database that no
longer exist.
Caused by math errors such as division by
zero.
Caused by overflowing the bound of an array.
Caused by bogus user I/O.
Type Of Exceptions
System exception
Arithmetic Exception
DividedByZeroException
OverFlowException
NullRefereceException
IndexOutOfRengeException
InvalidCastException
ApplicationException
UserDefineException
……………..
IOException
FileNotFoundException
…………..
WebException
Exception Handling
• .NET structured exception handling is a
technique well suited to deal with runtime
exceptions.
• Exception handling is a concept which help we
can handle undefined situation .
How Exception Handling??
• Exception handling by the Blocks.
• .Net FrameWork provides few blocks to handle
the Exceptions.
First one is try block.
Second one is catch block.
Third one is finally block.
The basic concept of exception handling are trrowing an exception
and catching it.this is illustrated in Fig.
Try block
Throw exception
Exception object
object
Statement that causes an exception creator
catch block
Exception handler
Statement that handles the exception
Finally block
Statement that always execute
Examples of Blocks
Try
{
int a=10,int b=0;
int c=a/b;
}
Catch(DevideByzeroException ex)
{
Response.Write(ex.ToString);
}
Finally
{
con.Close();
cmd.Distroy();
}
Throw our own Exception
• There may be times when we would like to throw our own exception .we
can do this by using the keyword throw as follow.ex:-
Class Myexception:ApplicationException Void check_age()
{ {
Myexception ex=new myexception(); If(cint(Textbox2.Text<18))
:Base(“your age must be greater then 18”); Throw ex;
} }
Try
{
Check_age();
}
Catch(Myexception ex)
{
Response.Write(“userdefine exception is :”+ex.ToString);
}
Thanks
It’s All About Our Presentation.
Have you Any Queries????