Exception Handling in C#
Prepared by:
Ezzat Harki
Copyright © 2013 Ezzat Harki
What Aim in This presentation
 Introduction to exception
 Advantage for pupil
 Mark for myself
Copyright © 2013 Ezzat Harki
What is Exception
 An exception is a problem that arises during the execution of a program. A C#
exception is a response to an exceptional circumstance that arises while a
program is running, such as an attempt to divide by zero.
Copyright © 2013 Ezzat Harki
This mechanism consist of
 Find the problem
 Inform that an error has occurred
 Receive the error information
 Take corrective action
Copyright © 2013 Ezzat Harki
Type of all Exception Class in C# library
Name
Access Violation Exception
AggregateException
AppDomainUnloadedException
ApplicationException
ArgumentException
ArgumentNullException
ArgumentOutOfRangeException
ArithmeticException
ArrayTypeMismatchException
BadImageFormatException
CannotUnloadAppDomainException
Copyright © 2013 Ezzat Harki
Cont.Type of all Exception Class in C# library
Name
ContextMarshalException
DataMisalignedException
DecoderFallbackException
DirectoryNotFoundException
DivideByZeroException
DllNotFoundException
DriveNotFoundException
DuplicateWaitObjectException
EncoderFallbackException
EndOfStreamException
EntryPointNotFoundException
ExecutionEngineException
Copyright © 2013 Ezzat Harki
Cont.Type of all Exception Class in C# library
Name
FieldAccessException
FileLoadException
FileNotFoundException
FormatException
IndexOutOfRangeException
InsufficientExecutionStackException
InsufficientMemoryException
InternalBufferOverflowException
InvalidCastException
InvalidDataException
InvalidOperationException
InvalidProgramException
InvalidTimeZoneException
IOException
Copyright © 2013 Ezzat Harki
Cont.Type of all Exception Class in C# library
Name
KeyNotFoundException
MemberAccessException
MethodAccessException
MissingFieldException
MissingMemberException
MissingMethodException
MulticastNotSupportedException
NotFiniteNumberException
NotImplementedException
NotSupportedException
NullReferenceException
ObjectDisposedException
OperationCanceledException
OutOfMemoryException
Copyright © 2013 Ezzat Harki
Cont.Type of all Exception Class in C# library
Name
OverflowException
PathTooLongException
PlatformNotSupportedException
RankException
StackOverflowException
SystemException
TaskCanceledException
TaskSchedulerException
TimeoutException
TimeZoneNotFoundException
TypeAccessException
TypeInitializationException
TypeLoadException
TypeUnloadedException
Copyright © 2013 Ezzat Harki
Cont.Type of all Exception Class in C# library
Name
UnauthorizedAccessException
UriFormatException
Copyright © 2013 Ezzat Harki
In C# Exception Handling is Managed by
that Keyword
 Try
 Catch
 Finally
 Throw
 checked
 Unchecked
Copyright © 2013 Ezzat Harki
Diagram working try & catch
Try block
Copyright © 2013 Ezzat Harki
Catch block
Statement that
Cause Exception
Statement that
Cause Exception
Diagram working try & catch wit Finally
Try block
Copyright © 2013 Ezzat Harki
finally
Catch blockfinally
Coding How to work try & catch with
finallyTry
{
statement;
//statement causing exception
}
Catch(exception type varable)
{
statement;
//error handling code
}
finally
{
//statement to be executed
statement;
}
Copyright © 2013 Ezzat Harki
It is Coding Example of Exception
 byte x = 129, y = 129, result;
 try
 {
 result =unchecked ((byte)(x + y));
 Console.WriteLine("The Result is Unchecked ", result);
 //at The Top Line Result is Unchecked But Get Wrong Result Becouse byte always can 256 count
 result =checked((byte)(x + y));
 Console.WriteLine("The Result is Checked ", result);
 //But in This Line Checked Result if Get Overflow Tell you
 }
 catch (OverflowException ovex)
 {
 Console.WriteLine(ovex.Message);
 }
Copyright © 2013 Ezzat Harki
Copyright © 2013 Ezzat Harki
If this presentation helped you please visit our page in facebook
and like it thanks for hearing
facebook.com/c.s.soran.university
NoteYou Can Download and Useful This Presentation
But Please Do Not Erase The Owner Name Ezzat Harki
If You Need Help Please Ask me at Facebook.com/Ezzat.Harky

Exception handling in c

  • 1.
    Exception Handling inC# Prepared by: Ezzat Harki Copyright © 2013 Ezzat Harki
  • 2.
    What Aim inThis presentation  Introduction to exception  Advantage for pupil  Mark for myself Copyright © 2013 Ezzat Harki
  • 3.
    What is Exception An exception is a problem that arises during the execution of a program. A C# exception is a response to an exceptional circumstance that arises while a program is running, such as an attempt to divide by zero. Copyright © 2013 Ezzat Harki
  • 4.
    This mechanism consistof  Find the problem  Inform that an error has occurred  Receive the error information  Take corrective action Copyright © 2013 Ezzat Harki
  • 5.
    Type of allException Class in C# library Name Access Violation Exception AggregateException AppDomainUnloadedException ApplicationException ArgumentException ArgumentNullException ArgumentOutOfRangeException ArithmeticException ArrayTypeMismatchException BadImageFormatException CannotUnloadAppDomainException Copyright © 2013 Ezzat Harki
  • 6.
    Cont.Type of allException Class in C# library Name ContextMarshalException DataMisalignedException DecoderFallbackException DirectoryNotFoundException DivideByZeroException DllNotFoundException DriveNotFoundException DuplicateWaitObjectException EncoderFallbackException EndOfStreamException EntryPointNotFoundException ExecutionEngineException Copyright © 2013 Ezzat Harki
  • 7.
    Cont.Type of allException Class in C# library Name FieldAccessException FileLoadException FileNotFoundException FormatException IndexOutOfRangeException InsufficientExecutionStackException InsufficientMemoryException InternalBufferOverflowException InvalidCastException InvalidDataException InvalidOperationException InvalidProgramException InvalidTimeZoneException IOException Copyright © 2013 Ezzat Harki
  • 8.
    Cont.Type of allException Class in C# library Name KeyNotFoundException MemberAccessException MethodAccessException MissingFieldException MissingMemberException MissingMethodException MulticastNotSupportedException NotFiniteNumberException NotImplementedException NotSupportedException NullReferenceException ObjectDisposedException OperationCanceledException OutOfMemoryException Copyright © 2013 Ezzat Harki
  • 9.
    Cont.Type of allException Class in C# library Name OverflowException PathTooLongException PlatformNotSupportedException RankException StackOverflowException SystemException TaskCanceledException TaskSchedulerException TimeoutException TimeZoneNotFoundException TypeAccessException TypeInitializationException TypeLoadException TypeUnloadedException Copyright © 2013 Ezzat Harki
  • 10.
    Cont.Type of allException Class in C# library Name UnauthorizedAccessException UriFormatException Copyright © 2013 Ezzat Harki
  • 11.
    In C# ExceptionHandling is Managed by that Keyword  Try  Catch  Finally  Throw  checked  Unchecked Copyright © 2013 Ezzat Harki
  • 12.
    Diagram working try& catch Try block Copyright © 2013 Ezzat Harki Catch block Statement that Cause Exception Statement that Cause Exception
  • 13.
    Diagram working try& catch wit Finally Try block Copyright © 2013 Ezzat Harki finally Catch blockfinally
  • 14.
    Coding How towork try & catch with finallyTry { statement; //statement causing exception } Catch(exception type varable) { statement; //error handling code } finally { //statement to be executed statement; } Copyright © 2013 Ezzat Harki
  • 15.
    It is CodingExample of Exception  byte x = 129, y = 129, result;  try  {  result =unchecked ((byte)(x + y));  Console.WriteLine("The Result is Unchecked ", result);  //at The Top Line Result is Unchecked But Get Wrong Result Becouse byte always can 256 count  result =checked((byte)(x + y));  Console.WriteLine("The Result is Checked ", result);  //But in This Line Checked Result if Get Overflow Tell you  }  catch (OverflowException ovex)  {  Console.WriteLine(ovex.Message);  } Copyright © 2013 Ezzat Harki
  • 16.
    Copyright © 2013Ezzat Harki If this presentation helped you please visit our page in facebook and like it thanks for hearing facebook.com/c.s.soran.university NoteYou Can Download and Useful This Presentation But Please Do Not Erase The Owner Name Ezzat Harki If You Need Help Please Ask me at Facebook.com/Ezzat.Harky