Download - Exception handling in c#
![Page 1: Exception handling in c#](https://reader036.vdocuments.mx/reader036/viewer/2022082322/53fc6cf98d7f72aa518b47a5/html5/thumbnails/1.jpg)
Exception Handling in C#
Prepared by:Ezzat Harki
Copyright © 2013 Ezzat Harki
![Page 2: Exception handling in c#](https://reader036.vdocuments.mx/reader036/viewer/2022082322/53fc6cf98d7f72aa518b47a5/html5/thumbnails/2.jpg)
What Aim in This presentation
Introduction to exception Advantage for pupil Mark for myself
Copyright © 2013 Ezzat Harki
![Page 3: Exception handling in c#](https://reader036.vdocuments.mx/reader036/viewer/2022082322/53fc6cf98d7f72aa518b47a5/html5/thumbnails/3.jpg)
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
![Page 4: Exception handling in c#](https://reader036.vdocuments.mx/reader036/viewer/2022082322/53fc6cf98d7f72aa518b47a5/html5/thumbnails/4.jpg)
This mechanism consist of
Find the problem Inform that an error has occurred Receive the error information Take corrective action
Copyright © 2013 Ezzat Harki
![Page 5: Exception handling in c#](https://reader036.vdocuments.mx/reader036/viewer/2022082322/53fc6cf98d7f72aa518b47a5/html5/thumbnails/5.jpg)
Type of all Exception Class in C# library
NameAccess Violation ExceptionAggregateExceptionAppDomainUnloadedExceptionApplicationExceptionArgumentExceptionArgumentNullExceptionArgumentOutOfRangeExceptionArithmeticExceptionArrayTypeMismatchExceptionBadImageFormatExceptionCannotUnloadAppDomainException
Copyright © 2013 Ezzat Harki
![Page 6: Exception handling in c#](https://reader036.vdocuments.mx/reader036/viewer/2022082322/53fc6cf98d7f72aa518b47a5/html5/thumbnails/6.jpg)
Cont.Type of all Exception Class in C# libraryNameContextMarshalExceptionDataMisalignedExceptionDecoderFallbackExceptionDirectoryNotFoundExceptionDivideByZeroExceptionDllNotFoundExceptionDriveNotFoundExceptionDuplicateWaitObjectExceptionEncoderFallbackExceptionEndOfStreamExceptionEntryPointNotFoundExceptionExecutionEngineException
Copyright © 2013 Ezzat Harki
![Page 7: Exception handling in c#](https://reader036.vdocuments.mx/reader036/viewer/2022082322/53fc6cf98d7f72aa518b47a5/html5/thumbnails/7.jpg)
Cont.Type of all Exception Class in C# library
NameFieldAccessExceptionFileLoadExceptionFileNotFoundExceptionFormatExceptionIndexOutOfRangeExceptionInsufficientExecutionStackExceptionInsufficientMemoryExceptionInternalBufferOverflowExceptionInvalidCastExceptionInvalidDataExceptionInvalidOperationExceptionInvalidProgramExceptionInvalidTimeZoneExceptionIOException
Copyright © 2013 Ezzat Harki
![Page 8: Exception handling in c#](https://reader036.vdocuments.mx/reader036/viewer/2022082322/53fc6cf98d7f72aa518b47a5/html5/thumbnails/8.jpg)
Cont.Type of all Exception Class in C# libraryName KeyNotFoundExceptionMemberAccessExceptionMethodAccessExceptionMissingFieldExceptionMissingMemberExceptionMissingMethodExceptionMulticastNotSupportedExceptionNotFiniteNumberExceptionNotImplementedExceptionNotSupportedExceptionNullReferenceExceptionObjectDisposedExceptionOperationCanceledExceptionOutOfMemoryException
Copyright © 2013 Ezzat Harki
![Page 9: Exception handling in c#](https://reader036.vdocuments.mx/reader036/viewer/2022082322/53fc6cf98d7f72aa518b47a5/html5/thumbnails/9.jpg)
Cont.Type of all Exception Class in C# libraryNameOverflowExceptionPathTooLongExceptionPlatformNotSupportedExceptionRankExceptionStackOverflowExceptionSystemExceptionTaskCanceledExceptionTaskSchedulerExceptionTimeoutExceptionTimeZoneNotFoundExceptionTypeAccessExceptionTypeInitializationExceptionTypeLoadExceptionTypeUnloadedException
Copyright © 2013 Ezzat Harki
![Page 10: Exception handling in c#](https://reader036.vdocuments.mx/reader036/viewer/2022082322/53fc6cf98d7f72aa518b47a5/html5/thumbnails/10.jpg)
Cont.Type of all Exception Class in C# libraryNameUnauthorizedAccessExceptionUriFormatException
Copyright © 2013 Ezzat Harki
![Page 11: Exception handling in c#](https://reader036.vdocuments.mx/reader036/viewer/2022082322/53fc6cf98d7f72aa518b47a5/html5/thumbnails/11.jpg)
In C# Exception Handling is Managed by that Keyword Try Catch Finally Throw checked Unchecked
Copyright © 2013 Ezzat Harki
![Page 12: Exception handling in c#](https://reader036.vdocuments.mx/reader036/viewer/2022082322/53fc6cf98d7f72aa518b47a5/html5/thumbnails/12.jpg)
Diagram working try & catch
Try block
Copyright © 2013 Ezzat Harki
Catch block
Statement thatCause Exception
Statement thatCause Exception
![Page 13: Exception handling in c#](https://reader036.vdocuments.mx/reader036/viewer/2022082322/53fc6cf98d7f72aa518b47a5/html5/thumbnails/13.jpg)
Diagram working try & catch wit Finally
Try block
Copyright © 2013 Ezzat Harki
finally
Catch block
finally
![Page 14: Exception handling in c#](https://reader036.vdocuments.mx/reader036/viewer/2022082322/53fc6cf98d7f72aa518b47a5/html5/thumbnails/14.jpg)
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
![Page 15: Exception handling in c#](https://reader036.vdocuments.mx/reader036/viewer/2022082322/53fc6cf98d7f72aa518b47a5/html5/thumbnails/15.jpg)
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); }
![Page 16: Exception handling in c#](https://reader036.vdocuments.mx/reader036/viewer/2022082322/53fc6cf98d7f72aa518b47a5/html5/thumbnails/16.jpg)
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