Execution of a Computer Program

  • #1

Main Question or Discussion Point

Hello Everyone, I want to know about various types of errors that can occur during the execution of a computer program? I am learning programming skills right now and Can anyone know about it? Or anyone knows which types of questions have put in a programming based profile as a beginner point?
 

Answers and Replies

  • #2
Here are the three main classes of computer coding errors you’re likely to run into:

1. Logical Errors
We will divide our errors into three classes: logical, syntax, and semantic. But be aware that these same classes can be either static (compile-time) or dynamic (run-time) in nature.

Logical errors are the hardest of all error types to detect. They do not cause the program to crash or simply not work at all, they cause it to “misbehave” in some way, rendering the wrong output of some kind. One example of a logic error is a null reference. Null reference errors are responsible for a huge chunk of application bugs, and they are usually very simple mistakes involving missing or wrong “computer logic.” It may be a property/field is null, a condition has prevented an object from being created, or a local variable field is declared but not initialized.

Logical errors “make sense” as to the computer language itself, but they simply don’t fit into the program correctly.

2. Syntax Errors
Syntax errors in computer programming differ from logical errors in that they don’t follow a correct sequence in the computer language.

With compiled languages, you will run into any syntax errors at compile-time, and they will have to be corrected before the program can run. For interpreted languages, a syntax error would pop up during the run time, and your error message might not even specify it’s a syntax problem. However, in both cases, the compiler/interpreter will give you the location of the syntax error, which makes it rather easy to find/fix.

In general, syntax errors are smaller, even single-digit, errors; while logic errors can involve larger sections of code and the general flow of the code. Some examples of syntax errors would be missing semicolons at a line’s end and an extra/missing bracket at end of a function.

3. Semantic Errors
Semantic errors are improper uses of “program statements.” Though different definitions of semantic error exist, we are saying here that logic errors produce wrong data while semantic errors produce nothing meaningful at all.

For more interview questions [advertising link deleted by Mentors]
 
Last edited by a moderator:
  • Like
Likes russ_watters and hutchphd
  • #3
33,632
5,287
We will divide our errors into three classes: logical, syntax, and semantic.
I'm not sure that logical errors are different from semantic errors. I've always considered them to be synonyms. Furthermore, if you search Wikipedia for "semantic errors" you are redirected to their page on logic errors.

For the OP, here are some examples of both types of error, in C. Here's a semantic error.
C:
int Average(int num1, int num2) {
    return num1 + num2 / 2;
}
It is syntactically correct, but it produces incorrect results because it erroneously divides only num2 rather than both num1 and num2.

Next, a syntax error.
C:
if (a > 0) then
    x = x + 2;
This is incorrect because there is no "then" keyword in C. Syntax errors are generally easier to spot because the program translator (compiler or interpreter) will fail to produce a working program, and will usually give you a clue as to where the problem is in the program.
 
  • Like
Likes sysprog and QuantumQuest
  • #4
33,632
5,287
Hello Everyone, I want to know about various types of errors that can occur during the execution of a computer program?
If you have written a program that was successfully compiled or interpreted, then there can't be any syntax errors -- errors caused by incorrect use of the language.

Aside from semantic or logical errors, from which the program produces incorrect results, some other types of errors include the following run-time errors:
  • Divide-by-zero error - The program attempted to divide a number by zero.
  • Overflow/underflow error - An arithmetic operation produced a result that was either too large or too negative to fit in the specified type, or was too small to be represented exactly.
  • Segment fault - A program attempted to read from or write to memory that it wasn't allowed to touch.
 
  • Like
Likes sysprog, QuantumQuest, Klystron and 1 other person
  • #5
11,794
5,402
Sometimes operator precedence rules vary from language to language and then its always good to use parentheses to make it clear what order of execution you want.

Sometimes folks use | the bitwise OR when they meant to use || the logical OR. Often found in conditionals used in IF or WHILE constructs. (java example)

Similarly for & the bitwise & and && the logical AND. (java example)
 
  • Like
Likes sysprog
  • #6
11,794
5,402
Multi-threaded programs can have race conditions where something is changed by another thread before you can use it.

https://en.wikipedia.org/wiki/Race_condition

I remember one example, did some delayed operations in a specific order. The operations were placed in a queue but the second operation had a higher priority than the first. So the programmer thought to execute 1 then 2 but the system executed 2 then 1. This can be quite challenging to figure out.

I think it had something to do with adding an entry to a windows scrollable select menu and then to scroll it down to that entry. What happened was it scrolled down then added the item to the menu so you didn't see it until you manually scrolled down. Scrolling down had a higher priority than adding an item to the menu.
 
Last edited:
  • Like
Likes sysprog and QuantumQuest
  • #7
Klystron
Gold Member
685
933
Hello Everyone, I want to know about various types of errors that can occur during the execution of a computer program? I am learning programming skills right now and Can anyone know about it? Or anyone knows which types of questions have put in a programming based profile as a beginner point?
Along with specific errors described in previous replies to this thread, @ankitdixit can learn about many execution and programming errors by studying previous threads on this sub-forum. Useful Insight articles appear at the top followed by threads listed in chronological order.

While not every thread and reply describe errors, many do and should provide guidance and direction to a beginner. Reading older threads will also expose one to different programming languages, different computing platforms and other points of view on error correction and avoidance.

Yes, anyone can know about errors and how to fix them. Learning proper programming standards and data structures along with computer languages will help avoid potential errors.
 
  • Like
Likes sysprog, QuantumQuest and jedishrfu
  • #8
Tom.G
Science Advisor
3,232
1,978
Logical error:
Lets say you were out partying and decided you needed to go home and get some sleep.

Arrive home
Enter living room
Open front door
Close front door

Oops! You just walked thru a closed door.:eek::H

Enjoy the journey!
Tom
 
  • Haha
Likes sysprog, QuantumQuest, Klystron and 1 other person
  • #9
11,794
5,402
A real world example is an automated milling machine where you're carving out a well in a part and instead of raising the routing bit before moving to the next spot to carve you just move and either break the part or break the bit.
 
  • Like
Likes sysprog, QuantumQuest and Klystron
  • #10
FactChecker
Science Advisor
Gold Member
5,578
2,056
There is an enormous variety of possible errors -- too many to list. (1) Some can be caught automatically by the computer and (2) others are up to you to spot. The main thing for you to learn is how to program so that both types are easier to spot and fix.
1) Use the tools that are provided by a modern programming environment. Many editors prompt you with the possible syntax options for code that you have started to type. Use that. Use debugging options as much as you can until the program is very thoroughly tested. Do not lump a lot of calculations or operations into single calculations; use multiple steps with intermediate results. Pay attention to any warning the compiler gives you and fix it.
2) Comment, comment, comment. Put references in your comments. Keep it simple. While debugging, don't be afraid to print a lot of intermediate results to files or to the terminal -- they are free and can save you a lot of time. Try to be as organized as you can. Use variable names and subroutine names that mean something. Do test runs on simple versions before you add more to make it complicated.

There are many more things that I could list, but these are the ones that seem to me to be most important.
 
Last edited:
  • Like
  • Informative
Likes QuantumQuest, sysprog and Tom.G
  • #11
Tom.G
Science Advisor
3,232
1,978
2) Comment, comment, comment.
I whole-heartedly agree!
Regardless of how sure you are that you will remember 'what', 'why', or 'how' two weeks from now, you won't! In fact you will be surprised at how much you have to 're-figure-out' in two days.

There are of course a few minor exceptions, one being:
Print "Hello World"
End

For me at least, the problem with no comments kicks in around a third to half a page; for simple programs.

Cheers,
Tom
 
  • Like
Likes QuantumQuest, sysprog and FactChecker
  • #12
1,615
967
I want to know about various types of errors that can occur during the execution of a computer program? I am learning programming skills right now...
Well, what I think the most useful part would be is a solid belief that the CPU is very rare to make an error: what happens when a program is running is mostly what the program should do - instead of what you expect it to do.
 
Last edited:
  • Like
Likes sysprog and FactChecker
  • #14
jim mcnamara
Mentor
3,905
2,292
Let's punt. The magnitude of possible errors and what they are called varies - almost Impossibly.
There is no really sensible and useful way to answer other than what @Mark44 did.

MicroFocus COBOL possible runtime errors/ compiletime errors were near 1000. This was back in 2009 when I was asked to research this kind of thing.

GNU C runtime error count for v3.04 (?) were 88 in errno.h - This is for C compiler running under Linux.
Some error codes were not supported on different platforms.

Given that there are dozens of operating systems and OS versions out there, all with their own unique error expressions. I run out of toes, fingers, and noses when I try to enumerate production languages, IDEs, Editors, precompilers, shells, DB languages like SQL, PL/SQL -

It renders trying to be explicit about errors as very unhelpful to a newbie.
 
Last edited:
  • Like
Likes Vanadium 50 and sysprog
  • #15
1,442
760
The first couple of chapters of the IBM manual that I referenced contain some cogent generalities that I think might be helpful.
 

Related Threads on Execution of a Computer Program

  • Last Post
Replies
10
Views
2K
Replies
4
Views
24K
Replies
18
Views
2K
  • Last Post
Replies
1
Views
2K
  • Last Post
Replies
3
Views
814
  • Last Post
Replies
4
Views
2K
  • Last Post
Replies
2
Views
1K
  • Last Post
Replies
1
Views
2K
Top