Execution of a Computer Program

In summary, a semantic error is when the programmer uses the wrong statement in a program, while a logical error is when the computer language doesn't follow a correct sequence. Syntax errors are smaller, single-digit errors, while logic errors can involve larger sections of code and the general flow of the code.
  • #1
ankitdixit
6
1
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?
 
Technology news on Phys.org
  • #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
khatrivijaysingh1994 said:
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
ankitdixit said:
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
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
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
ankitdixit said:
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
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
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
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
FactChecker said:
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
ankitdixit said:
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
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
The first couple of chapters of the IBM manual that I referenced contain some cogent generalities that I think might be helpful.
 

Related to Execution of a Computer Program

1. How does a computer execute a program?

When a computer executes a program, it follows a specific set of instructions called the program's algorithm. The computer's central processing unit (CPU) reads each instruction, interprets it, and performs the necessary operations.

2. What is the role of the operating system in program execution?

The operating system manages the execution of a program by allocating resources such as memory, processing power, and input/output devices. It also ensures that multiple programs can run simultaneously without interfering with each other.

3. What is the difference between source code and machine code?

Source code is written by programmers using a high-level programming language, such as Java or Python. It is human-readable and needs to be translated into machine code, which is a set of instructions that the computer can directly execute.

4. What are the common types of errors that can occur during program execution?

There are three main types of errors that can occur during program execution: syntax errors, runtime errors, and logical errors. Syntax errors occur when the program violates the rules of the programming language, while runtime errors occur during program execution due to unexpected events. Logical errors, on the other hand, do not cause the program to crash, but they produce incorrect results.

5. How can you monitor the execution of a computer program?

There are various tools and techniques for monitoring the execution of a computer program, such as debugging tools, performance profiling tools, and code coverage tools. These tools help identify and fix any errors or bottlenecks in the program, ensuring efficient execution.

Similar threads

  • Programming and Computer Science
Replies
16
Views
1K
  • Programming and Computer Science
Replies
22
Views
939
  • Programming and Computer Science
Replies
7
Views
688
  • Programming and Computer Science
Replies
3
Views
1K
  • Programming and Computer Science
2
Replies
65
Views
2K
  • Programming and Computer Science
Replies
9
Views
2K
  • Programming and Computer Science
Replies
9
Views
1K
  • Programming and Computer Science
2
Replies
54
Views
3K
  • Programming and Computer Science
Replies
29
Views
2K
  • Programming and Computer Science
Replies
1
Views
734
Back
Top