Difference in compile and execution error

4

A compilation error would be one that the IDE already warns before it even compiles, such as missing a semicolon, correct? But what about the execution error? It would be, for example, a Exception ?

    
asked by anonymous 27.09.2018 / 16:29

2 answers

4

The overall response has already been given in What's the difference between compile time and run time? .

No matter how it happens, what matters is that it occurs when the application is running. More robust languages tend to keep errors from running. But there are several cases that this is impossible. There are situations that you only know that the error occurred at the time it is occurring, you have no way to anticipate that it will occur or potentially will occur mainly but not only when it involves external data that is only known when it is running.

An example is a division by 0 when 0 is the value of a variable that only knows its value in execution, either by data entry, or because in order to reach it it has gone through several steps that it would be impossible or very difficult to conclude that it is 0 at compile time.

Typical examples are those that are indicated by the operating system, database, etc. These are runtime errors outside your application control.

There are errors that can be considered programming. Because whenever it is possible that it goes wrong you should check before and do not let the error. Division by 0 is one of them. Arguments passed to functions are other, index of a collection of data out of range as well.

Each language uses a way to indicate this, the exception is one of them and is the most basic one used by Java.

But the error is detected in other ways before throwing the exception, the exception is only the surface. It does not happen by itself, out of nowhere. There is an algorithm that determined that something is wrong and it is thrown. This can be up to something that comes out externally and even from the processor.

Whenever an exception is thrown we can say that there was an error. Java has the culture of treating even invalid data as an error, which for many is a wrong concept, is using exception for something not exceptional.

Any error that can be detected at compile time should be. The lexical errors, syntax and semantics of the code can be detected at this point.

Technically, there is no way to report an error before compiling. The compiler is that detects the errors. It is possible for an IDE to invoke a compiler to do this before generating an executable.

    
27.09.2018 / 16:38
0

That's right.

Compile error: When an invalid character or wrong syntax is found in the code.

Execution error: After the code is compiled, when executing the project, there is some exception of sql, casting, some calculation error, etc. That is, the execution error would be a logical error and not a "grammar" error, let's say.

    
27.09.2018 / 16:38