Types of programming errors

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 causes our program to behave unexpectedly and it is no doubt that the well versed and experienced programmers also makes mistakes. Programming error are generally known as Bugs and the process to remove bugs from program is called as Debug/Debugging.

There are basically three types of error:

  1. Syntax error or Compilation error
  2. Runtime error or Execution error
  3. 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 error are thrown by the compilers and will prevent your program from running. These errors are most common to beginners. It is also called as Compile time error or Syntax error. These errors are easy to debug.

Example:

  • misspelling a statement, eg writing iput instead of input or typing Int instead of int
  • missing brackets, eg opening a bracket, but not closing it
  • missing semicolon
  • errors in the sequence of expressions

Runtime error (Execution error)
Run Time errors are generated when the program is running and leads to the abnormal behavior or termination of the program. The general cause of Run time errors is because 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.

Logical error
Logical error will cause your program to perform undesired operations which you didn't intended your program to perform. These errors occur generally due to improper logic used in 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.

Table for comparison of types of errors

Type of error Compilation Execution
Syntax error
Run-time error
Logic error

Source: codeforwin.org

Questions:

1. Explain what is programming error.

2. Describe the term "syntax error".

3. Explain what difference between run-time error and logic error.

Exercises:

Ex. 1

Ex. 2

Writing error-free code test questions

Ex. 3

Find logic errors

 

Exam questions:

 

Категория: Debugging | Добавил: bzfar77 (20.09.2020)
Просмотров: 102 | Теги: Compilation, run-time error, Execution, logic error, types of programmimg errors, syntax error | Рейтинг: 0.0/0
Всего комментариев: 0
avatar