SlideShare a Scribd company logo
1 of 12
Abhishek Pachisia
B-Tech(IT)-II yr
09SETIT144
Exceptions
  – Indicate problems that occur during a program’s
    execution
  – Occur infrequently
Exception handling
  – Can resolve exceptions
     • Allow a program to continue executing or
     • Notify the user of the problem and
     • Terminate the program in a controlled manner
  – Makes programs robust and fault-tolerant
• An exception is a condition that cannot be resolved within the context of the
  operation that caused it. (examples?)
• To throw an exception is to signal that such a condition has occurred.
• To catch an exception is to transfer control to an exception handling routine,
  altering the normal execution flow of the program.
• Because exceptions are outside the normal operation of a program the normal,
  default action is to write out an error message and terminate the offending
  process.
• Older languages did not provide for exception handling as part of the
  language definition (Fortran, COBOL, C).
• Newer languages have added language constructs to facilitate exception
  handling (Ada, C++, Java).
• Most operating systems provide some sort of signal mechanism that can be
  used to provide a form of exception handling.
Exceptions can occur at many levels:

 Hardware/operating system level.
   • Arithmetic exceptions; divide by 0.
   • Memory access violations; stack over/underflow.
 Language level.
   • Type conversion; illegal values, improper casts.
   • Bounds violations; illegal array indices.
   • Bad references; null pointers.
 Program level.
   • User defined exceptions.
 Intermixing program and error-handling logic
    – Pseudo code outline
        Perform a task
        If the preceding task did not execute correctly
          Perform error processing
        Perform next task
        If the preceding task did not execute correctly
          Perform error processing
 Sometimes it is hard to distinguish an exception from normal
  processing.
 Makes the program difficult to read, modify, maintain and debug.
 Impacts performance.

Note:– In most large systems, code to handle errors and exceptions represents
“>80%” of the total code of the system.
Enclose code that may have an error in try block.
Follow with one or more catch blocks.
    Each catch block has an exception handler
If exception occurs and matches parameter in catch block, code in catch
block executed
If no exception thrown, exception handlers skipped and control resumes
after catch blocks
throw point - place where exception occurred
    Control cannot return to throw point
• Use assert
   – If assertion false, the program terminates

• Ignore exceptions
   – Use this "technique" on casual, personal programs - not commercial!

• Abort the program
   – Appropriate for nonfatal errors give appearance that program functioned
     correctly
   – Inappropriate for mission-critical programs, can cause resource leaks

• Set some error indicator
   – Program may not check indicator at all points there error could occur
•Test for the error condition
   − Issue an error message and call exit.
   − Pass error code to environment.
• setjump and longjump
   −In <csetjmp>
   −Jump out of deeply nested function calls back to an error handler.
   −Dangerous - unwinds the stack without calling destructors for automatic
   objects (more later).
•Specific errors
   −Some have dedicated capabilities for handling them
   −If new fails to allocate memory new handler function executes to deal
   with problem
throw - indicates an exception has occurred
  Usually has one operand (sometimes zero) of any type.
      −If operand an object, called an exception object.
      −Conditional expression can be thrown
  Code referenced in a try block can throw an exception.
  Exception caught by closest exception handler.
  Control exits current try block and goes to catch handler (if it
  exists).
  Exception not required to terminate program
     −However, terminates block where exception occurred
o Exception handlers are in catch blocks.
oCaught if argument type matches throw type.
         If not caught then terminate called which (by default) calls abort
oIf no handler matches thrown object
    •Searches next enclosing try block
    •If none found, terminate called
    •If found, control resumes after last catch block
    •If several handlers match thrown object, first one found is executed
ocatch parameter matches thrown object when
    •They are of the same type.
    • The catch parameter is a public base class of the thrown object.
    •The catch parameter is a base-class pointer/ reference type and the thrown
    object is a derived-class pointer/ reference type.
•The catch handler is catch( ... ).
   •Thrown const objects have const in the parameter type.
oUnreleased resources
   •Resources may have been allocated when exception thrown
   catch handler should delete space allocated by new and close any opened
   files.
ocatch handlers can throw exceptions
   •Exceptions can only be processed by outer try blocks.
oUsed when an exception handler cannot process an exception.
oRethrow exception with the statement:
    throw;
    •No arguments
    •If no exception thrown in first place, calls terminate
oHandler can always rethrow exception, even if it performed some
processing
oRethrown exception detected by next enclosing try block

More Related Content

What's hot (20)

Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
 
exception handling in java.ppt
exception handling in java.pptexception handling in java.ppt
exception handling in java.ppt
 
Exception handling
Exception handlingException handling
Exception handling
 
Java Server Pages(jsp)
Java Server Pages(jsp)Java Server Pages(jsp)
Java Server Pages(jsp)
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
 
Java - Exception Handling
Java - Exception HandlingJava - Exception Handling
Java - Exception Handling
 
Exception handling in java
Exception handling  in javaException handling  in java
Exception handling in java
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Exception Handling in JAVA
Exception Handling in JAVAException Handling in JAVA
Exception Handling in JAVA
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
 
Presentation on-exception-handling
Presentation on-exception-handlingPresentation on-exception-handling
Presentation on-exception-handling
 
Exception Handling in Java
Exception Handling in JavaException Handling in Java
Exception Handling in Java
 
Phases of Compiler
Phases of CompilerPhases of Compiler
Phases of Compiler
 
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++
 
Synchronization.37
Synchronization.37Synchronization.37
Synchronization.37
 
Java threads
Java threadsJava threads
Java threads
 
Exception handling
Exception handlingException handling
Exception handling
 
Parsing
ParsingParsing
Parsing
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
 
L14 exception handling
L14 exception handlingL14 exception handling
L14 exception handling
 

Viewers also liked

Viewers also liked (10)

encapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloadingencapsulation, inheritance, overriding, overloading
encapsulation, inheritance, overriding, overloading
 
2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding2CPP08 - Overloading and Overriding
2CPP08 - Overloading and Overriding
 
Seminar on polymorphism
Seminar on polymorphismSeminar on polymorphism
Seminar on polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Method overloading and constructor overloading in java
Method overloading and constructor overloading in javaMethod overloading and constructor overloading in java
Method overloading and constructor overloading in java
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
polymorphism
polymorphism polymorphism
polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 

Similar to Exception handling

Exception handling
Exception handlingException handling
Exception handlingpooja kumari
 
Java Exceptions and Exception Handling
 Java  Exceptions and Exception Handling Java  Exceptions and Exception Handling
Java Exceptions and Exception HandlingMaqdamYasir
 
Exception handling
Exception handlingException handling
Exception handlingMinal Maniar
 
exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2thenmozhip8
 
exception-handling-in-java.ppt
exception-handling-in-java.pptexception-handling-in-java.ppt
exception-handling-in-java.pptJAYESHRODGE
 
Introduction to java exceptions
Introduction to java exceptionsIntroduction to java exceptions
Introduction to java exceptionsSujit Kumar
 
exceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.pptexceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.pptyjrtytyuu
 
Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010Clay Helberg
 
Exception Handling in UiPath.pptx
Exception Handling in UiPath.pptxException Handling in UiPath.pptx
Exception Handling in UiPath.pptxApurbaSamanta9
 
Design byexceptions
Design byexceptionsDesign byexceptions
Design byexceptionsAsif Tasleem
 
Errors and exception
Errors and exceptionErrors and exception
Errors and exceptionRishav Upreti
 
Lecture 1 Try Throw Catch.pptx
Lecture 1 Try Throw Catch.pptxLecture 1 Try Throw Catch.pptx
Lecture 1 Try Throw Catch.pptxVishuSaini22
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in JavaVadym Lotar
 
Chap2 exception handling
Chap2 exception handlingChap2 exception handling
Chap2 exception handlingraksharao
 
Java-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handlingJava-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handlingraksharao
 
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 allHayomeTakele
 

Similar to Exception handling (20)

Exception handling
Exception handlingException handling
Exception handling
 
Java Exceptions and Exception Handling
 Java  Exceptions and Exception Handling Java  Exceptions and Exception Handling
Java Exceptions and Exception Handling
 
Exception handling
Exception handlingException handling
Exception handling
 
exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2exception-handling-in-java.ppt unit 2
exception-handling-in-java.ppt unit 2
 
exception-handling-in-java.ppt
exception-handling-in-java.pptexception-handling-in-java.ppt
exception-handling-in-java.ppt
 
Introduction to java exceptions
Introduction to java exceptionsIntroduction to java exceptions
Introduction to java exceptions
 
exceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.pptexceptionvdffhhhccvvvv-handling-in-java.ppt
exceptionvdffhhhccvvvv-handling-in-java.ppt
 
Chelberg ptcuser 2010
Chelberg ptcuser 2010Chelberg ptcuser 2010
Chelberg ptcuser 2010
 
Exception Handling in UiPath.pptx
Exception Handling in UiPath.pptxException Handling in UiPath.pptx
Exception Handling in UiPath.pptx
 
Design byexceptions
Design byexceptionsDesign byexceptions
Design byexceptions
 
Errors and exception
Errors and exceptionErrors and exception
Errors and exception
 
Lecture 1 Try Throw Catch.pptx
Lecture 1 Try Throw Catch.pptxLecture 1 Try Throw Catch.pptx
Lecture 1 Try Throw Catch.pptx
 
F6dc1 session6 c++
F6dc1 session6 c++F6dc1 session6 c++
F6dc1 session6 c++
 
Exception handling
Exception handlingException handling
Exception handling
 
Exception hierarchy
Exception hierarchyException hierarchy
Exception hierarchy
 
Exceptions in Java
Exceptions in JavaExceptions in Java
Exceptions in Java
 
Exception
ExceptionException
Exception
 
Chap2 exception handling
Chap2 exception handlingChap2 exception handling
Chap2 exception handling
 
Java-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handlingJava-Unit 3- Chap2 exception handling
Java-Unit 3- Chap2 exception handling
 
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
 

More from Abhishek Pachisia (20)

Telecom Industry
Telecom IndustryTelecom Industry
Telecom Industry
 
Strategic alignment model (SAM)
Strategic alignment model (SAM)Strategic alignment model (SAM)
Strategic alignment model (SAM)
 
V.G. siddhartha
V.G. siddharthaV.G. siddhartha
V.G. siddhartha
 
Boeing- The Frontiers
Boeing- The FrontiersBoeing- The Frontiers
Boeing- The Frontiers
 
Top Management of 5 recognized comapanies
Top Management of 5 recognized comapaniesTop Management of 5 recognized comapanies
Top Management of 5 recognized comapanies
 
Fourier transform
Fourier transformFourier transform
Fourier transform
 
Inference engine
Inference engineInference engine
Inference engine
 
Work breakdown structure
Work breakdown structureWork breakdown structure
Work breakdown structure
 
IEEE 802.11
IEEE 802.11IEEE 802.11
IEEE 802.11
 
Cloud Service Models
Cloud Service ModelsCloud Service Models
Cloud Service Models
 
Perl
PerlPerl
Perl
 
Rpc
RpcRpc
Rpc
 
Program Evaluation and Review Technique (PERT)
Program Evaluation and Review Technique (PERT)Program Evaluation and Review Technique (PERT)
Program Evaluation and Review Technique (PERT)
 
Hydrogen energy
Hydrogen energyHydrogen energy
Hydrogen energy
 
Rms titanic
Rms titanicRms titanic
Rms titanic
 
Vb.net (loop structure)
Vb.net (loop structure)Vb.net (loop structure)
Vb.net (loop structure)
 
Matrix Representation Of Graph
Matrix Representation Of GraphMatrix Representation Of Graph
Matrix Representation Of Graph
 
Tree
TreeTree
Tree
 
File System Implementation
File System ImplementationFile System Implementation
File System Implementation
 
Condolence letter
Condolence letterCondolence letter
Condolence letter
 

Recently uploaded

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Recently uploaded (20)

08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 

Exception handling

  • 2. Exceptions – Indicate problems that occur during a program’s execution – Occur infrequently Exception handling – Can resolve exceptions • Allow a program to continue executing or • Notify the user of the problem and • Terminate the program in a controlled manner – Makes programs robust and fault-tolerant
  • 3. • An exception is a condition that cannot be resolved within the context of the operation that caused it. (examples?) • To throw an exception is to signal that such a condition has occurred. • To catch an exception is to transfer control to an exception handling routine, altering the normal execution flow of the program. • Because exceptions are outside the normal operation of a program the normal, default action is to write out an error message and terminate the offending process. • Older languages did not provide for exception handling as part of the language definition (Fortran, COBOL, C). • Newer languages have added language constructs to facilitate exception handling (Ada, C++, Java). • Most operating systems provide some sort of signal mechanism that can be used to provide a form of exception handling.
  • 4. Exceptions can occur at many levels:  Hardware/operating system level. • Arithmetic exceptions; divide by 0. • Memory access violations; stack over/underflow.  Language level. • Type conversion; illegal values, improper casts. • Bounds violations; illegal array indices. • Bad references; null pointers.  Program level. • User defined exceptions.
  • 5.  Intermixing program and error-handling logic – Pseudo code outline Perform a task If the preceding task did not execute correctly Perform error processing Perform next task If the preceding task did not execute correctly Perform error processing  Sometimes it is hard to distinguish an exception from normal processing.  Makes the program difficult to read, modify, maintain and debug.  Impacts performance. Note:– In most large systems, code to handle errors and exceptions represents “>80%” of the total code of the system.
  • 6. Enclose code that may have an error in try block. Follow with one or more catch blocks. Each catch block has an exception handler If exception occurs and matches parameter in catch block, code in catch block executed If no exception thrown, exception handlers skipped and control resumes after catch blocks throw point - place where exception occurred Control cannot return to throw point
  • 7. • Use assert – If assertion false, the program terminates • Ignore exceptions – Use this "technique" on casual, personal programs - not commercial! • Abort the program – Appropriate for nonfatal errors give appearance that program functioned correctly – Inappropriate for mission-critical programs, can cause resource leaks • Set some error indicator – Program may not check indicator at all points there error could occur
  • 8. •Test for the error condition − Issue an error message and call exit. − Pass error code to environment. • setjump and longjump −In <csetjmp> −Jump out of deeply nested function calls back to an error handler. −Dangerous - unwinds the stack without calling destructors for automatic objects (more later). •Specific errors −Some have dedicated capabilities for handling them −If new fails to allocate memory new handler function executes to deal with problem
  • 9. throw - indicates an exception has occurred Usually has one operand (sometimes zero) of any type. −If operand an object, called an exception object. −Conditional expression can be thrown Code referenced in a try block can throw an exception. Exception caught by closest exception handler. Control exits current try block and goes to catch handler (if it exists). Exception not required to terminate program −However, terminates block where exception occurred
  • 10. o Exception handlers are in catch blocks. oCaught if argument type matches throw type. If not caught then terminate called which (by default) calls abort oIf no handler matches thrown object •Searches next enclosing try block •If none found, terminate called •If found, control resumes after last catch block •If several handlers match thrown object, first one found is executed ocatch parameter matches thrown object when •They are of the same type. • The catch parameter is a public base class of the thrown object. •The catch parameter is a base-class pointer/ reference type and the thrown object is a derived-class pointer/ reference type.
  • 11. •The catch handler is catch( ... ). •Thrown const objects have const in the parameter type. oUnreleased resources •Resources may have been allocated when exception thrown catch handler should delete space allocated by new and close any opened files. ocatch handlers can throw exceptions •Exceptions can only be processed by outer try blocks.
  • 12. oUsed when an exception handler cannot process an exception. oRethrow exception with the statement: throw; •No arguments •If no exception thrown in first place, calls terminate oHandler can always rethrow exception, even if it performed some processing oRethrown exception detected by next enclosing try block