# Types of Programming Errors

October 12, 2020

Programming errors (such as syntax errors, logical errors, etc.), more commonly known as ‘Bugs’ in computing lingo, are the bane of any software developer. Since machines are increasingly being used in automated mode, with onboard embedded systems or computers controlling their functioning, a programming error can have drastic consequences.

There have been cases of space shuttles and planes crashing due to software bugs in embedded computing equipment. A single loophole left in operating system code can provide an entry point to hackers who can exploit the vulnerability, putting computer security at risk. Ergo, errors need to be taken very seriously as we increasingly rely on computers.

Let’s understand different types of errors in programming.

## Types of Programming Errors

There are seven types of programming errors.

• Syntax Errors
• Logical Errors
• Compilation Errors
• Runtime Errors
• Arithmetic Errors
• Resource Errors
• Interface Errors

Let’s understand these errors one by one and how you can avoid them.

### 1. What is Syntax Error?

A syntax error in computer science is an error in the syntax of a coding or programming language, entered by a programmer. Syntax errors are caught by a software program called a compiler, and the programmer must fix them before the program is compiled and then run.

Syntax errors are different from errors that affect programs during run time. Many logical errors in computer programming do not get caught by the compiler, because although they may cause grievous errors as the program runs, they do conform to the program’s syntax.

In other words, the computer cannot tell whether a logical error is going to create problems, but it can tell when code does not conform to the syntax because the understanding of that syntax is built into the compiler’s native intelligence.

Another aspect of understanding syntax errors is that they demonstrate how, unlike humans, computers cannot use input that is not perfectly designed. The lack of a period or comma in a sentence or command, or two swapped letters in a word, confounds the compiler and makes its work impossible.

On the other hand, human readers can spot typographical errors and understand them in the context of what they are reading. It is likely that as computers evolve through the coming decades, engineers may be able to create compilers and systems that can handle some types of syntax errors; even now, in some compiling environments, tools can auto-correct syntax errors on-site.

### 2. What is Logical Error?

A logical error is an error in a program’s source code that gives way to an unanticipated and erroneous behavior. A logical error is classified as a type of runtime error that can result in a program producing incorrect output. It can also cause the program to crash when running.

Logical errors are not always easy to recognize immediately. This is due to the fact that such errors, unlike syntax errors, are valid when considered in the language, but do not produce the intended behavior. These can occur in both interpreted and compiled languages.

For example, in PHP, when “if ($i=1) {…}” is incorrectly entered instead of “if ($i==1) {….},” the former means “become” while the latter means “is equal to.” The incorrect if statement would always return TRUE as assigning 1 to the variable $i. In the correct version, though, the statement only returns TRUE when the value of variable$i is equal to 1.

The syntax in the incorrect case is perfectly correct as per the language. So, the code would compile successfully without producing any syntax errors. However, during the runtime of the code, the resultant output may be wrong, thus showing that a certain logic error has occurred.

Logic errors tend to be hidden in the source code and can typically be harder to determine and debug, unlike syntax errors that are recognized at compile time.

### 3. What is Compilation Error?

Some programming languages require a compilation step. The compilation is where your high-level language converts into a lower-level language that the computer can understand better. A compilation or compile-time error happens when the compiler doesn’t know how to turn your code into lower-level code.

In our syntax error example, if we were compiling print(‘hello’, the compiler would stop and tell us it doesn’t know how to convert this into a lower-level language because it expected a ) after the ‘.
If there is a compile-time error in your software, you won’t be able to get it tested or launched.
Like syntax errors, you will get better at avoiding these with time, but in general, the best thing you can do is get early feedback when it happens.

Compilation happens across all files of your project at the same time. If you’ve made lots of changes and see lots of compiler warnings or errors, it can be very daunting. By running the compiler often, you will get the feedback you need sooner, and you will more easily know where to address the issues.

### 4. What is Runtime Error?

A Runtime Error is an error that occurs at the time of running or executing a program. When this error occurs, the program may hang or crash displaying an error message. There are many reasons for a runtime error, like when the program enters an infinite loop, it triggers the runtime error. Sometimes, it also occurs due to the user’s fault.

For example, a program requires a numerical value to process the result, but if the user enters any value other than the required one, say, an alphabetic character, the program may show a runtime error.

Runtime errors are particularly annoying because they directly impact your end user. A lot of these other errors will happen when you’re at your computer working on the code. These errors occur when the system is running and can stop someone from doing what they need to do.

Make sure you have good error reporting in place to capture any runtime errors and automatically open up new bugs in your ticketing system. Try and learn from each bug report so that in the future you can guard against this type of error.

Making use of frameworks and community-maintained code is an excellent way of minimizing these types of errors because the code is in many different projects, so it will have already encountered and fixed many issues.

### 5. What is Arithmetic Error?

An arithmetic error is a type of logic error that involves mathematics. A typical example when performing a division equation is that you cannot divide by zero without causing an issue.

Very few people would write 5 / 0, but you might not think that the size of something in your system might sometimes be zero, which would lead to this type of error.

ages.max / ages.min could return an error if either ages.max or ages.min were zero.
Arithmetic errors can generate logic errors as we’ve discussed, or even run-time errors in the case of divide by zero.

Having functional tests that always include edge cases like zero, or negative numbers is an excellent way to stop these arithmetic errors in their tracks.

### 6. What is Resource Error?

Sometimes, a program can force the computer it’s running on to attempt to allocate more resources (processor power, random access memory, disk space, etc.) than it has. This results in the program becoming bugged or even causing the entire system to crash.

### 7. What is Interface Error?

Interface errors occur when there is a disconnect between how you meant your program to be used and how it is actually used. Most things in software follow standards. If the input your program receives doesn’t conform to the standards, you might get an interface error.

For example, an interface error might happen if you have an API that requires that specific parameters are set and those parameters are not set.

Unless handled correctly, interface errors will look like an error on your side when it is an error on the caller’s side. This can lead to frustration from both sides.

Programming errors are inevitable. Understanding common programming errors and learning how to deal with them is an essential skill that every programmer should have. Get better at spotting them early, but know you will never be perfect.

Hopefully, this article has prepared you for the different types of errors in programming and made sense of some of the most common error messages for you.

## FAQs

### What are the different types of programming errors?

The different types of programming errors are Syntax Errors, Logical Errors, Compilation Errors, Runtime Errors, Arithmetic Errors, Resource Errors, and Interface Errors.

### What is the most common programming error?

While syntax errors are some of the most common programming errors, the good news is that they’re also some of the easiest to find and fix, as the compiler usually will identify the location of any of these errors. Syntax errors are the coding equivalent of grammatical errors.

## Conclusion

An error resulting from bad code in some program involved in producing the erroneous result. There can be various reasons for these errors. Programming errors are broadly divided into seven types – Syntax Errors, Logical Errors, Compilation Errors, Runtime Errors, Arithmetic Errors, Resource Errors, and Interface Errors.