Compile-time and Run-time Errors

Programmers, while executing their code of any language will come across two terms, compile-time and Run time errors. Let us briefly know what they are.

Compilation Errors

Every code must be syntactically correct to pass compilation. The compilation is the process that compiler checks for syntaxes in the user-written code. Syntaxes are not just special characters but they do have some meaning. For example, semicolon (;) in C means the end of the statement, the opening and closing curly braces ({,}) defines the opening and closing of a block or scope respectively. So, syntaxes should not be missed to avoid compilation errors.

Let us see some examples to demonstrate more clearly.

#include<stdio.h>
int main()
{
int a=10 // semicolon missed
printf(“%d”,a);
return 0;
}

In the above code, we have missed a semicolon at the end of the declaration of ‘a’ variable. This is syntactically incorrect. So, the compiler results in an error, error: expected ‘,’ or ‘;’ before ‘printf’

#include<stdio.h>
int main()
{
int a=10,b=5;
if(a>b)
    {
       printf(“%d”,a);
    }
else
   {
      printf(“%d”,b);
   //closing brace for else part is missed
return 0;
}  

Here, the closing scope brace is missed for else part. So, there will be a compilation error saying error: expected declaration or statement at end of input

Run time Errors

after the successful compilation of our program, we’ll take the next step. We will run our program. This is where after the success of which, you will get your output. The errors that occurred during this run-time are called Run-time errors. Let us see some of the run time errors.

A run time error means that the program is compiled successfully, but it failed due to run time error or crashed. There are different types of run time errors. Let us learn them properly.

  1. SIGSEGV

This error means ‘Segmentation Fault’. Some of the causes of this error are, by an out-of-scope array index causing a buffer overflow, an incorrectly initialized pointer, etc. this error occurs when the program trying to access the outside the memory allocated for it.

2. SIGXFSZ

This error says “output limit exceeded”. Your program has expected too much data as output.

3. SIGFPE

This indicates a “floating point error”. This is the most famous error. Usually demonstrating run time errors start with this error. This error usually occurs when you are trying to divide a number by zero, or trying to take a square root of a negative number.

4. NZEC

This means “non-zero exit code”. This error means that the program exited returning a value other than 0. This may simply mean that we have forgotten the ‘return 0’ statement in c/c++ languages.

In interpreted languages like python, this error usually means that our program either crashed or raised an uncaught exception.

5. SIGABRT

This error occurs when the program is aborted in the middle of the execution. This error is raised by the program itself.

6. OTHER

This error is generated when we use too much of memory. For example, a very large sized array.

7. MLE

This indicates “Memory Limit Exceeded”. This error is generated when you try to allocate memory beyond the memory limit indicated. This can occur if you declare a very large array or some other data structures.

Categories: News