16
Exception Handling in C# Prepared by: Ezzat Harki Copyright © 2013 Ezzat Harki

Exception handling in c#

Embed Size (px)

DESCRIPTION

 

Citation preview

Page 1: Exception handling in c#

Exception Handling in C#

Prepared by:Ezzat Harki

Copyright © 2013 Ezzat Harki

Page 2: Exception handling in c#

What Aim in This presentation

Introduction to exception Advantage for pupil Mark for myself

Copyright © 2013 Ezzat Harki

Page 3: Exception handling in c#

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#

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#

Type of all Exception Class in C# library

NameAccess Violation ExceptionAggregateExceptionAppDomainUnloadedExceptionApplicationExceptionArgumentExceptionArgumentNullExceptionArgumentOutOfRangeExceptionArithmeticExceptionArrayTypeMismatchExceptionBadImageFormatExceptionCannotUnloadAppDomainException

Copyright © 2013 Ezzat Harki

Page 6: Exception handling in c#

Cont.Type of all Exception Class in C# libraryNameContextMarshalExceptionDataMisalignedExceptionDecoderFallbackExceptionDirectoryNotFoundExceptionDivideByZeroExceptionDllNotFoundExceptionDriveNotFoundExceptionDuplicateWaitObjectExceptionEncoderFallbackExceptionEndOfStreamExceptionEntryPointNotFoundExceptionExecutionEngineException

Copyright © 2013 Ezzat Harki

Page 7: Exception handling in c#

Cont.Type of all Exception Class in C# library

NameFieldAccessExceptionFileLoadExceptionFileNotFoundExceptionFormatExceptionIndexOutOfRangeExceptionInsufficientExecutionStackExceptionInsufficientMemoryExceptionInternalBufferOverflowExceptionInvalidCastExceptionInvalidDataExceptionInvalidOperationExceptionInvalidProgramExceptionInvalidTimeZoneExceptionIOException

Copyright © 2013 Ezzat Harki

Page 8: Exception handling in c#

Cont.Type of all Exception Class in C# libraryName KeyNotFoundExceptionMemberAccessExceptionMethodAccessExceptionMissingFieldExceptionMissingMemberExceptionMissingMethodExceptionMulticastNotSupportedExceptionNotFiniteNumberExceptionNotImplementedExceptionNotSupportedExceptionNullReferenceExceptionObjectDisposedExceptionOperationCanceledExceptionOutOfMemoryException

Copyright © 2013 Ezzat Harki

Page 9: Exception handling in c#

Cont.Type of all Exception Class in C# libraryNameOverflowExceptionPathTooLongExceptionPlatformNotSupportedExceptionRankExceptionStackOverflowExceptionSystemExceptionTaskCanceledExceptionTaskSchedulerExceptionTimeoutExceptionTimeZoneNotFoundExceptionTypeAccessExceptionTypeInitializationExceptionTypeLoadExceptionTypeUnloadedException

Copyright © 2013 Ezzat Harki

Page 10: Exception handling in c#

Cont.Type of all Exception Class in C# libraryNameUnauthorizedAccessExceptionUriFormatException

Copyright © 2013 Ezzat Harki

Page 11: Exception handling in c#

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#

Diagram working try & catch

Try block

Copyright © 2013 Ezzat Harki

Catch block

Statement thatCause Exception

Statement thatCause Exception

Page 13: Exception handling in c#

Diagram working try & catch wit Finally

Try block

Copyright © 2013 Ezzat Harki

finally

Catch block

finally

Page 14: Exception handling in c#

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#

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#

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