A programmer can make mistakes while writing a program, and hence, the program may not execute or may generate wrong output. The process of identifying and removing such mistakes , also known as bugs or errors , from a program is called debugging .
Errors occurring in programs can be categorised as:
1. Syntax errors - These errors arise when the interpreter cannot understand a line of code with wrong syntax.
(10 + 11
Syntax error: Missing closing parentheses
2. Logical errors - A logical error produces an undesired output but without abrupt termination of the execution of the program. Since the program interprets successfully even when logical errors are present in it, it is sometimes difficult to identify these errors.Logical errors are also called semantic errors as they occur when the meaning of the program (its semantics) is not correct.
- we wish to find the average of two numbers 10 and 12
- we write the code as 10 + 12/2, it would run successfully and produce the result 16.
- Surely, 16 is not the average of 10 and 12.
- The correct code to find the average should have been (10 + 12)/2 to give the correct output as 11.
3. Runtime errors - A runtime error causes abnormal termination of program while it is executing. Runtime error is when the statement is correct syntactically, but the interpreter cannot execute it. Runtime errors do not appear until after the program starts running or executing.