Book contents
- Frontmatter
- Contents
- Preface
- PART ONE FOUNDATIONS
- 1 Cornerstones of OOP
- 2 Objects
- 3 Class Construction
- 4 Relationships between Classes
- 5 GUIs: Basic Concepts
- 6 Implementing Simple GUIs in Java
- 7 Errors and Exceptions
- 8 Recursion
- PART TWO DATA STRUCTURES
- Appendix A Unified Modeling Language Notation
- Appendix B Complexity of Algorithms
- Appendix C Installing and Using Foundations Classes
- Index
7 - Errors and Exceptions
from PART ONE - FOUNDATIONS
Published online by Cambridge University Press: 05 June 2012
- Frontmatter
- Contents
- Preface
- PART ONE FOUNDATIONS
- 1 Cornerstones of OOP
- 2 Objects
- 3 Class Construction
- 4 Relationships between Classes
- 5 GUIs: Basic Concepts
- 6 Implementing Simple GUIs in Java
- 7 Errors and Exceptions
- 8 Recursion
- PART TWO DATA STRUCTURES
- Appendix A Unified Modeling Language Notation
- Appendix B Complexity of Algorithms
- Appendix C Installing and Using Foundations Classes
- Index
Summary
In a world with perfect users, perfect programs, and perfect hardware we would not have to concern ourselves with exceptions. Users would never enter incorrect data (e.g., enter an alphabetic character when a number is required). Hardware would never fail. Printers would always be on when our software attempts to access them. A hard drive would never be full when a program attempts to write to it. Such a world does not exist.
Brittle programs do indeed crash because of some failure in the input, the program logic, or the physical system supporting the application. Some crashes occur because of hardware interrupts (failures in a hardware component) or synchronization conflict (two or more segments of code attempting to modify the same data simultaneously). Program crashes may be catastrophic. If the rudder computer control system on an aircraft were to go down or the computer guidance system on a rocket were to fail, a catastrophe of major proportions might occur. Often a program crash results in a loss of input data – not a catastrophe but a profound annoyance to the user. One's confidence in using a program often disappears if such loss of data occurs frequently.
Exception handling involves defensive programming tactics that ensure a more benign outcome if your programming application should fail. Exception handling can ensure that input data are saved before a program is terminated, can notify the user that an input or hardware error has occurred and allow program execution to continue, or can bring the system to a stable and safe state before exiting the application.
- Type
- Chapter
- Information
- Fundamentals of OOP and Data Structures in Java , pp. 119 - 134Publisher: Cambridge University PressPrint publication year: 2000