What is the Difference Between Runtime Error and Logical Error

The main difference between runtime error and logical error is that a runtime error is an error that occurs due to an illegal operation in the program while a logical error is an error that occurs due to a fault in the algorithm of the program.

Runtime error and logical error are two types of errors. An error is an unexpected outcome of a program. Errors can affect the proper execution of the program. Therefore, it is important to fix errors. Apart from these two error types, there is another error type called syntax error, which occurs due to mistakes in the program syntax.

Key Areas Covered

1. What is a Runtime Error
     – Definition, Cause, Detection, Output
2. What is a Logical Error
     – Definition, Cause, Detection, Output
3. What is the Difference Between Runtime Error and Logical Error
     – Comparison of Key Differences

Key Terms

Logical Error, Runtime Error

Difference Between Runtime Error and Logical Error - Comparison Summary

What is a Runtime Error

A runtime error is an error that occurs at runtime. In other words, the computer detects these errors at the time of running the program. It will cause the program to stop or crash. It will display a diagnostic message on the screen.

What is the Difference Between Runtime Error and Logical Error

Furthermore, a runtime error occurs due to an illegal operation in the program. For example, dividing a number by zero will give an error at runtime. Moreover, accessing a memory location that is not available is also a runtime error.

What is a Logical Error

An algorithm is a sequence of steps to follow when writing a program. Logical errors occur due to an issue in the algorithm. These errors will not cause the program to terminate execution. Instead, it will give a wrong output. The programmer has to read and check every statement to identify a logical error. Therefore, it is a difficult task. For example, if the programmer use subtraction (-) instead of summation (+), it will give a wrong output. This kind of error is a logical error.

Difference Between Runtime Error and Logical Error

Definition

A runtime error is an error that occurs while running a computer program while a logical error is an error in a program that causes it to operate incorrectly, but not to terminate abnormally. This is the main difference between runtime error and logical error.

Cause

Describing the above further, the runtime error occurs due to an illegal operation in the program while the logical error occurs due to an issue in the algorithm.

Detection

Moreover, another difference between runtime error and logical error is that the computers detect runtime errors at the time of running the program. On the other hand, the programmer has to check every statement in the program to determine the logical error.

Output

Further difference between runtime error and logical error is that the runtime errors cause the program to stop execution or to crash. However, the logical errors do not cause the program to stop the execution, but it will give a wrong output. 

Examples

Runtime errors can occur due to reasons such as dividing a number by zero or because of accessing a memory location that is not available. In contrast, logical errors can occur due to wrong use of operators and an inappropriate sequence of instructions. This is another difference between runtime error and logical error. 

Conclusion

The main difference between runtime error and logical error is that a runtime error is an error that occurs due to an illegal operation in the program while a logical error is an error that occurs due to a fault in the algorithm of the program.

Reference:

1. PGC Lectures: Programming Errors & Types, Syntax Error, Runtime Error, Logical Error, Online Learners, 8 Jan. 2017, Available here.

Image Courtesy:

1. “Stio iks” By Rehoerigjoigjrtioj – Own work (CC BY-SA 3.0) via Commons Wikimedia

About the Author: Lithmee

Lithmee holds a Bachelor of Science degree in Computer Systems Engineering and is reading for her Master’s degree in Computer Science. She is passionate about sharing her knowldge in the areas of programming, data science, and computer systems.

Leave a Reply