Types of errors


Three types of errors

There are basically three types of errors that you must contend with when writing computer programs:

  • Syntax errors
  • Runtime errors
  • Logic errors

Generally speaking, the errors become more difficult to find and fix as you move down the above list.

Syntax errors

In effect, syntax errors represent grammar errors in the use of the programming language.Syntax error are easier to detect as now a days most of the programming platform comes with error debugging features like Visual Studio, Ecllipse , Turbo C.

Common examples are:

  • Misspelled variable and function names
  • Missing semicolons
  • Improperly matches parentheses, square brackets, and curly braces
  • Incorrect format in selection and loop statements

For Example while declaring a variable in C Program this could be one example of Syntax Error:

int a

instead of writing

int a;


Runtime errors

Runtime errors occur when a program with no syntax errors asks the computer to do something that the computer is unable to reliably do.It is difficult to detect in coding environment until program is tested. To detect runtime error a programmer must try to execute program with different inputs.

Common examples are:

  • Trying to divide by a variable that contains a value of zero
  • Trying to open a file that doesn’t exist

There is no way for the compiler to know about these kinds of errors when the program is compiled.


Logic errors

Logic errors occur when there is a design flaw in your program.This is most important of all the error types as it causes a program to produce undesired or unexpected output. In addition this type of error are difficult to detect as there won’t be any grammatical mistake to verify or inputs to check with.

Common examples are:

  • Multiplying when you should be dividing
  • Adding when you should be subtracting
  • Opening and using data from the wrong file
  • Displaying the wrong message

Leave a Reply

Your email address will not be published. Required fields are marked *