1.4 Identifying and Correcting Errors
Correcting Errors College Board Assignment
Common Errors:
To start, it’s important to note that no one is perfect. Errors are bound to happen but identifying, understanding, and fixing thoses errors is what matters more. There are 4 main types of errors when developing a program; Logic, Syntax, Run-time, and Overflow errors.
-
Logic errors are errors that are caused due to the programmer making a mistake in the algorithm. This causes the program to behave unexpectedly. A logic error can result in events in the program taking place in times that they are not suppose to happen in.
-
Syntax errors are very small mistakes made by the programmer that doesn’t match with the language. It could be a typo, unnecessary code, missing necessary code, missing characters or added characters. Characters include colon, semicolon, parenthesis, indentations, quotes, and so much more. These mistakes will cause the program to shut down.
-
Run-time errors happen when a program stops while it is running. This event is also known as “crashing” and the error is normally referred to as a “bug”. A run-time error can be caused by dividing by zero, wrong inputed data type, or many other errors that are commonly caused by incorrect data.
-
Over-flow errors occur in a program when it is required to perform a calculation that is not possible for it to run. The values in the calculations are outside the set range of values of the program. This is caused due to memory allocation constraints of the program’s language, resulting in restrictions.
Methods to Correct Errors:
-
IDEs: Syntax errors are the easiest errors to fix because most IDEs display information on where and when there is a syntax error.
-
Test Cases: Unlike syntax errors, logic errors are more difficult to found because the IDEs doesn’t help you and it would normally look like nothing is wrong. This is when programmers use test cases. Test cases are a set of actions(like inputs) that are used to check if they get the correct result.
-
Hand Tracing: Another testing strategy is hand tracing. Hand tracing is putting in values of variables in a loop to find out if the outcome is correct. This is most useful with loops and other small code segments that repeat a number of times.
-
Extra Outputs: Lastly, a programmer could just add extra outputs. This strategy is used so that the programmer could find where the error is in the program. When the error is fixed, the extra output is normally removed.