12.5.3.5 describe a syntax error in a programming 12.5.3.1 describe run-time errors in a programming 12.5.3.6 describe a logic error in a programming
Types of programming errors
Errors are the mistakes or faults in the program that cause our program to behave unexpectedly and it is no doubt that well-versed and experienced programmers also make mistakes. Programming errors are generally known as Bugs and the process to remove bugs from the program is called Debug/Debugging.
There are basically three types of error:
Syntax error or Compilation error
Run-time error or Execution error
Logical error
Syntax error or Compilation error
Compilation errors are the most common error occurred due to typing mistakes or if you don't follow the proper syntax of the specific programming language. These errors are most common to beginners. These errors are thrown by the compilers and will prevent your program from running. It is also called a Compile time error or Syntax error. The compiler highlights the error by pointing to the line of the program and displays a description of each error, so these errors are easy to debug.
Example:
misspelling a statement, eg writing iputinstead of input
missing brackets, eg opening a bracket, but not closing it
missing semicolon
errors in the sequence of expressions
Run-time error (Execution error)
Run-time errors are generated when the program is running and lead to abnormal behavior or termination of the program. The general cause of run-time errors is that your program is trying to perform an operation that is impossible to carry out.
Example:
Dividing any number by zero,
Accessing any file that doesn't exist,
Negative value under a square root,
Calling invalid functions,
Not handling certain input correctly (ex. not appropriate data type),
Out of bounds of array indices.
Logical error
The logical error will cause your program to perform undesired operations that you didn't intend your program to perform. These errors occur generally due to improper logic used in the program. These types of errors are difficult to debug.
Examples:
errors in the performed computation, eg. using multiplication (a * b) instead of adding (a + b)
errors in the performed condition, eg. using "<" instead of "<="
unintentionally creating a situation where an infinite loop may occur
incorrectly using brackets in calculations
unintentionally using the same variable name at different points in the program for different purposes.