Types of errors
- Syntax errors
- Logical errors
- Run time errors
- Latent errors
1. Syntax error
Any violation of rules of the language results in syntax error. The compiler can detect and isolate such errors. When syntax errors are present, the compilation fails and is terminated after listing the errors and the line numbers in the source program, where the errors have occurred. Such error occurs when a computer language compiler cannot understand a command entered by the user. It is easy to correct the syntax error.
2. Run-time (Execution) Errors
Errors such as mismatch of data types or referencing an out of range array element go undetected by the compiler. A program with these mistakes will run but produce the erroneous result. Isolating a run time error is usually a difficult task.
These errors are encountered after error free compilation, at the time of execution of the program. Some typical examples are:
- Data incorrect or in wrong order
- Incorrect file name
- Infinite loops
- Divide check errors – these errors appear when a quantity is divided by zero.
- Correct outputs only for selected data.
3. Logical errors
These errors are related to the logic of the program execution. Such actions as taking the wrong path, failure to consider a particular condition and incorrect order of evaluation of statements belong to this category. Logical errors do not show up as compiler- generated error messages. Rather, they cause incorrect results. These errors are primarily due to a poor understanding of the problem, incorrect translation of the algorithm and a lack of clarity of the hierarchy (precedence) of operators.
For Example: for calculating net salary the formula is:
Net Salary = Basic Salary + Allowances – Deductions
But through the oversight, while coding, the formula is written as:
Net Salary = Basic Salary - Allowances + Deductions
Such errors can be detected by dry run.
4. Latent errors
It is a ‘hidden’ error that shows up only when a particular set of data is used.
Example:
ratio = (x + y)/(p - q)
The above expression generates error when p = q.
Debugging
After the program has been developed there may be different types of errors involved which have to be corrected for the program to run successfully, this is called debugging. Debugging is the process of isolating and correcting the errors.
Debugging Tools (Techniques):
Different methods are available for finding the location of execution errors and logical errors within a program. Such methods are generally referred to as debugging techniques. There are different types of debugging tools
- Error Isolation
- Single stepping (Trace into and step over)
- Watches
- Break Points
- Tracing
1. Error Isolation
Error isolation is useful for locating an error resulting in a diagnostic message. If the general location of the error is not known, it can be frequently be found by temporarily deleting a portion of the program and then rerunning the program to see if the error disappears. The temporary deletion is accomplished by surrounding the instructions with markers (/* and */), causing the enclosed instructions to become comments. If the error message then disappears, the deleted portion of the program contains the source of the error.
2. Single Stepping
Stepping refers to the execution of one instruction at a time, typically by pressing a function key to execute each instruction. In Turbo C++, for example, stepping can be carried out by pressing either function key F7 or F8. (F8 steps over subordinate functions, where as F7 steps through the function). By stepping through out the program, we can determine which instructions produce the erroneous result or generate error messages.
3. Watches
A watch value is the value of a variable or an expression which is displayed continuously as the program executes. Thus we can see the changes in a watch value as they occur, in response to the program logic. By monitoring a few carefully selected watch values, we can often determine where the program begins to generate incorrect or unexpected values.
In Turbo C++, watch values can be defined by selecting Add Watch from the Debug menu and then specifying one or more variables or expressions in the resulting dialog box. The watch values will then be displayed within a separate window as the program executes.
4. Break Points
A breakpoint is a temporary stopping point within a program. Each break point is associated with a particular instruction within the program. When the program is executed, the program execution will temporarily stop at the breakpoint, before the instruction is executed. The execution may ten be resumed, until the next breakpoint is encountered. Breakpoints are often used in conjunction with watch values, by observing the current watch value at each breakpoint as the program executes.
To set a breakpoint in Turbo C++, select Add Breakpoint from the Debug menu, and ten provide the requested information in the resulting dialog box. Or, select a particular line within the program and designate it a breakpoint by pressing function key F5. The breakpoint may later be disabled by again pressing F5. (Function key F5 is called a “toggle” in this context, since it turns the breakpoint on or off by successively pressing the key.)
5. Tracing
Tracing involves the use of printf statement to display the values assigned to certain key variables, or to display the values that are calculated internally at various locations within the program.
Testing
Testing is the process of reviewing and executing a program with the intent of detecting errors, which may belong to any of the four kinds of errors discussed above.