Error Handling
CHAPTER OUTLINE
PROGRAMMING ERRORS
STRUCTURED EXCEPTION HANDLING
UNSTRUCTURED EXCEPTION HANDLING
INTRODUCTION
Chapter Objectives
At the end of the chapter, the student should be able to:
understand the different types of programming errors;
use unstructured error handling in writing algorithms; and
use unstructured error handling in writing algorithms.
2
INTRODUCTION
Programming Errors
When computer programs are written, there will always be a possibility of writing an erroneous code known as bugs.
Bugs make a program perform differently from the designed algorithm, or it might not run at all. Hence, when there is an error in program, it has to be located and corrected.
INTRODUCTION
Locating Errors
The process of finding and fixing errors in a program is called debugging.
Debugging is an iterative process which involves repeatedly running and writing the program until all errors are gone.
In most cases, a program need not to be stopped for debugging through the process of Edit and Continue in
Visual BASIC (program will stop where the error occurred and may be continued after editing).
CATEGORIES OF ERRORS
Three Major Categories of Errors
1. Compilation Errors
Compilation errors are errors due to syntax issues such as misspelling, improper syntax or wrong keyword use.
Code with compilation errors are highlighted with a blue underline as shown below:
Note that, the presence of compilation error prevent a program from running.
CATEGORIES OF ERRORS
Three Major Categories of Errors (cont.)
2. Run Time Errors
Run time errors occur when a combination of data and code causes an invalid condition during runtime in what otherwise appears to be a valid code (e.g. when the user enters a string data for a numeric variable) during coding.
In the example below, a text value was placed in a numeric variable:
CATEGORIES OF ERRORS