Error Handling in Programing Exercises – Assignment Example

The paper "Error Handling in Programing Exercises" is a wonderful example of an assignment on logic and programming. This study explores two major options of error handling in programming exercises. One of the options it focuses on is the progressive testing for errors and exceptions as the program is being developed. This, according to Goodenough (1975), means that errors are only detected when they occur. The programmer detects errors during inputs and when retrieving the output data from the file in which they are stored. The second option is to write a script for dynamic handling of errors and exceptions. The scripts ensure that the program does not experience the effect of the error but receives the report about the nature of any possible error.  Advantages and disadvantages of testing for error conditions as compared to using exception handling when performing input or output
Testing enables the programmer to detect errors and exceptions during programming and to manage them before final implementation. This is an assurance that the error is eliminated permanently.
The challenge with testing for errors is that it can only test and manage known errors. Unknown errors, however, continue existing, unlike the exception handling that detects and prevents all possible errors in a block of program codes (Schilling, 1998). The programmer must have prior knowledge of the errors that he or she expects, hence, design the program in a manner to avoid the errors, or to use input data that does not violate the running of the program (Goodenough, 1975). Testing of errors cannot manage unpredictable errors which may occur during the input and output. Secondly, the errors are only detected when they occur; unlike in exception handling where errors are prevented from occurring and are reported promptly.
Why almost all programmers, in almost all cases, moved to use exception handling for input or output
Exception handling is more convenient for most of the programmers first because it eliminates all program errors and reports them when detected. Secondly, it relieves the programmer of the need to identify all possible errors as it is in error testing. Exceptional handling is detective and preventive, unlike error testing that is corrective. From the viewpoint of Kiniry (2006), exceptional handling is able to prevent errors that occur during input and output and enables the program used to have a new opportunity to provide correct input and avoid the effect of the errors. Thirdly, exception handling provides more information about the errors and exceptions, than does error testing.
Situations other than input or output that you might find exception handling useful
Errors not only occur during the input and output stages. There are other situations in which exception handling becomes very useful. These include arithmetic operations. For example, when a number is divided by zero or when the arithmetic formula is incorrect, there occurs exception, which needs to be handled (Hof, Mössenböck and Pirkelbauer, 1997). The second situation is in the application of a logical statement. For example, when a statement is written as follows:
1 = 0
2 + 2 = 10
True = False
These statements are logically incorrect and may cause logical errors (Hutton and Wright, 2004). The third situation is when the name of the input file is not found. This is because either the file name specified in the program differs from the actual name of the input file used, or the route directory of the file is incorrect.
Whether exception handling could be the preferred approach to use for those situations as well
Exception handling is preferred in the three situations mentioned. I arithmetic operations, it is possible that a programmer might have used a parameter with a zero value as a denominator in calculation. This can only be prevented from causing an error by the exception handler. In the logical statements, the errors have non-reversible effects and can only be prevented from occurring by the “try”, “catch” and “throw” constructs of exception handlers. The third situation is about the location and the name of the data file. According to Gabriel and Steele (2008), the exception handling mechanism is able to report the source of error during the execution and provide a timely opportunity for remedy.
The two options for detecting and managing errors are both useful. However, it is easier and more reliable to work with exception handling because it is proactive and dynamic in the detection of unexpected errors. Inherently, a user does not have ideas about the errors to expect. With the error testing, he or she must have a list of all errors to manage. I exception handling, there is no need to worry as it manages all possible errors and exceptions. It is recommendable for all programmers to use exception handling as opposed to error testing method.