Upload
ezzat-harky
View
157
Download
1
Embed Size (px)
DESCRIPTION
Citation preview
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
NameAccess Violation ExceptionAggregateExceptionAppDomainUnloadedExceptionApplicationExceptionArgumentExceptionArgumentNullExceptionArgumentOutOfRangeExceptionArithmeticExceptionArrayTypeMismatchExceptionBadImageFormatExceptionCannotUnloadAppDomainException
Copyright © 2013 Ezzat Harki
Cont.Type of all Exception Class in C# libraryNameContextMarshalExceptionDataMisalignedExceptionDecoderFallbackExceptionDirectoryNotFoundExceptionDivideByZeroExceptionDllNotFoundExceptionDriveNotFoundExceptionDuplicateWaitObjectExceptionEncoderFallbackExceptionEndOfStreamExceptionEntryPointNotFoundExceptionExecutionEngineException
Copyright © 2013 Ezzat Harki
Cont.Type of all Exception Class in C# library
NameFieldAccessExceptionFileLoadExceptionFileNotFoundExceptionFormatExceptionIndexOutOfRangeExceptionInsufficientExecutionStackExceptionInsufficientMemoryExceptionInternalBufferOverflowExceptionInvalidCastExceptionInvalidDataExceptionInvalidOperationExceptionInvalidProgramExceptionInvalidTimeZoneExceptionIOException
Copyright © 2013 Ezzat Harki
Cont.Type of all Exception Class in C# libraryName KeyNotFoundExceptionMemberAccessExceptionMethodAccessExceptionMissingFieldExceptionMissingMemberExceptionMissingMethodExceptionMulticastNotSupportedExceptionNotFiniteNumberExceptionNotImplementedExceptionNotSupportedExceptionNullReferenceExceptionObjectDisposedExceptionOperationCanceledExceptionOutOfMemoryException
Copyright © 2013 Ezzat Harki
Cont.Type of all Exception Class in C# libraryNameOverflowExceptionPathTooLongExceptionPlatformNotSupportedExceptionRankExceptionStackOverflowExceptionSystemExceptionTaskCanceledExceptionTaskSchedulerExceptionTimeoutExceptionTimeZoneNotFoundExceptionTypeAccessExceptionTypeInitializationExceptionTypeLoadExceptionTypeUnloadedException
Copyright © 2013 Ezzat Harki
Cont.Type of all Exception Class in C# libraryNameUnauthorizedAccessExceptionUriFormatException
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 thatCause Exception
Statement thatCause Exception
Diagram working try & catch wit Finally
Try block
Copyright © 2013 Ezzat Harki
finally
Catch block
finally
Coding How to work try & catch with finallyTry
{statement;//statement causing exception }
Catch(exception type varable){statement;//error handling code}
finally{//statement to be executedstatement;}
Copyright © 2013 Ezzat Harki
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
If this presentation helped you please visit our page in facebook and like it thanks for hearing
facebook.com/c.s.soran.university
Note You Can Download and Useful This Presentation But Please Do Not Erase The Owner Name Ezzat HarkiIf You Need Help Please Ask me at Facebook.com/Ezzat.Harky