SlideShare a Scribd company logo
1 of 16
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

More Related Content

What's hot

Exception handler
Exception handler Exception handler
Exception handler
dishni
 
14 exception handling
14 exception handling14 exception handling
14 exception handling
jigeno
 
Exception handling
Exception handlingException handling
Exception handling
Ravi Sharda
 
Advantages Over Conventional Error Handling in OOP
Advantages Over Conventional Error Handling in OOPAdvantages Over Conventional Error Handling in OOP
Advantages Over Conventional Error Handling in OOP
Raju Dawadi
 
Php Condition Flow
Php Condition FlowPhp Condition Flow
Php Condition Flow
lotlot
 
Exception handling chapter15
Exception handling chapter15Exception handling chapter15
Exception handling chapter15
Kumar
 

What's hot (20)

From OOP to FP : the validation case
From OOP to FP : the validation caseFrom OOP to FP : the validation case
From OOP to FP : the validation case
 
Exception handling
Exception handlingException handling
Exception handling
 
Programming katas for Software Testers - CounterStrings
Programming katas for Software Testers - CounterStringsProgramming katas for Software Testers - CounterStrings
Programming katas for Software Testers - CounterStrings
 
C++ ala
C++ alaC++ ala
C++ ala
 
What is Exception Handling?
What is Exception Handling?What is Exception Handling?
What is Exception Handling?
 
Exception Handling in C++
Exception Handling in C++Exception Handling in C++
Exception Handling in C++
 
PHP - Introduction to PHP Error Handling
PHP -  Introduction to PHP Error HandlingPHP -  Introduction to PHP Error Handling
PHP - Introduction to PHP Error Handling
 
C# Exceptions Handling
C# Exceptions Handling C# Exceptions Handling
C# Exceptions Handling
 
Exception Handling In Java
Exception Handling In JavaException Handling In Java
Exception Handling In Java
 
Exception handler
Exception handler Exception handler
Exception handler
 
14 exception handling
14 exception handling14 exception handling
14 exception handling
 
Exception handling
Exception handlingException handling
Exception handling
 
Advantages Over Conventional Error Handling in OOP
Advantages Over Conventional Error Handling in OOPAdvantages Over Conventional Error Handling in OOP
Advantages Over Conventional Error Handling in OOP
 
Php Condition Flow
Php Condition FlowPhp Condition Flow
Php Condition Flow
 
Exception handling chapter15
Exception handling chapter15Exception handling chapter15
Exception handling chapter15
 
Php exceptions
Php exceptionsPhp exceptions
Php exceptions
 
Handling error & exception in php
Handling error & exception in phpHandling error & exception in php
Handling error & exception in php
 
Python Programming Essentials - M21 - Exception Handling
Python Programming Essentials - M21 - Exception HandlingPython Programming Essentials - M21 - Exception Handling
Python Programming Essentials - M21 - Exception Handling
 
Testing 101
Testing 101Testing 101
Testing 101
 
Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++Exception Handling in object oriented programming using C++
Exception Handling in object oriented programming using C++
 

Similar to Exception handling in c

Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
ChaAstillas
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
priyankazope
 
Exception Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception HandlingException Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception Handling
AboMohammad10
 
Ch-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allCh-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for all
HayomeTakele
 

Similar to Exception handling in c (20)

Java coding pitfalls
Java coding pitfallsJava coding pitfalls
Java coding pitfalls
 
UNIT 2.pptx
UNIT 2.pptxUNIT 2.pptx
UNIT 2.pptx
 
Decompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 PresentationDecompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 Presentation
 
Exceptions overview
Exceptions overviewExceptions overview
Exceptions overview
 
Exception Handling
Exception HandlingException Handling
Exception Handling
 
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
Do I need tests when I have the compiler - Andrzej Jóźwiak - TomTom Dev Day 2020
 
ASP.NET 05 - Exception Handling And Validation Controls
ASP.NET 05 - Exception Handling And Validation ControlsASP.NET 05 - Exception Handling And Validation Controls
ASP.NET 05 - Exception Handling And Validation Controls
 
Switch case and looping
Switch case and loopingSwitch case and looping
Switch case and looping
 
exceptions in java
exceptions in javaexceptions in java
exceptions in java
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Exception Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception HandlingException Handling Exception Handling Exception Handling
Exception Handling Exception Handling Exception Handling
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
exception handling.pptx
exception handling.pptxexception handling.pptx
exception handling.pptx
 
Java unit 11
Java unit 11Java unit 11
Java unit 11
 
Best Coding Practices For Android Application Development
Best Coding Practices For Android Application DevelopmentBest Coding Practices For Android Application Development
Best Coding Practices For Android Application Development
 
Exception handling
Exception handlingException handling
Exception handling
 
JAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programmingJAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programming
 
JAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programmingJAVA Tutorial- Do's and Don'ts of Java programming
JAVA Tutorial- Do's and Don'ts of Java programming
 
Switch case looping
Switch case loopingSwitch case looping
Switch case looping
 
Ch-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for allCh-1_5.pdf this is java tutorials for all
Ch-1_5.pdf this is java tutorials for all
 

Recently uploaded

Recently uploaded (20)

Microsoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - QuestionnaireMicrosoft CSP Briefing Pre-Engagement - Questionnaire
Microsoft CSP Briefing Pre-Engagement - Questionnaire
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
ADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptxADP Passwordless Journey Case Study.pptx
ADP Passwordless Journey Case Study.pptx
 
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
Human Expert Website Manual WCAG 2.0 2.1 2.2 Audit - Digital Accessibility Au...
 
Design Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptxDesign Guidelines for Passkeys 2024.pptx
Design Guidelines for Passkeys 2024.pptx
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
AI mind or machine power point presentation
AI mind or machine power point presentationAI mind or machine power point presentation
AI mind or machine power point presentation
 
UiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overviewUiPath manufacturing technology benefits and AI overview
UiPath manufacturing technology benefits and AI overview
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
Introduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDMIntroduction to use of FHIR Documents in ABDM
Introduction to use of FHIR Documents in ABDM
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdfFrisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
Frisco Automating Purchase Orders with MuleSoft IDP- May 10th, 2024.pptx.pdf
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Top 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development CompaniesTop 10 CodeIgniter Development Companies
Top 10 CodeIgniter Development Companies
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
2024 May Patch Tuesday
2024 May Patch Tuesday2024 May Patch Tuesday
2024 May Patch Tuesday
 

Exception handling in c

  • 1. Exception Handling in C# Prepared by: Ezzat Harki Copyright © 2013 Ezzat Harki
  • 2. What Aim in This 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 consist of  Find the problem  Inform that an error has occurred  Receive the error information  Take corrective action Copyright © 2013 Ezzat Harki
  • 5. 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
  • 6. 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
  • 7. 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
  • 8. 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
  • 9. 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
  • 10. Cont.Type of all Exception Class in C# library Name UnauthorizedAccessException UriFormatException Copyright © 2013 Ezzat Harki
  • 11. In C# Exception Handling 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 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
  • 15. 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
  • 16. 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