Compile and run error difference

A compile error would be one that the IDE already warns before compiling, such as the lack of a semicolon, correct? But what about the execution error? Would it be for example a Exception?

Author: Maniero, 2018-09-27

3 answers

The overall answer has already been given in What is the difference between" compile time "and"run time"?.

No matter how it occurs, what matters is that it occurs when the application is running. More robust languages tend to prevent errors from staying at runtime. 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 of anticipating that it will occur or potentially occur, mostly, 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 at execution, either by data input or because to get into it went through several steps that it would be impossible or very difficult to conclude that it is 0 at compile time.

Typical examples are those indicated by the operating system, database, etc. Are operating errors out of control of your application.

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

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

But the error is detected by other ways before throw the exception, the exception is only the surface. It does not occur alone, out of nowhere. There is an algorithm that determines that something is wrong and it is thrown. This can even be something that comes informed 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 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. Errors in the lexicon, syntax and semantics of the code can be detected at this time.

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

Runtime error after compiling

 7
Author: Maniero, 2020-08-07 14:04:46

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 running the project, you find some sql exception, casting, some calculation error, etc. That is, the execution error would be a logical error and not a "grammar" error say.

 1
Author: Leandro Kojima, 2018-09-27 14:46:27

Build error is the error that does not let you generate the executable or the library, so that you run/run it.

Execution error is one that, as the name says, happens only when the executable or library is run/run.

An example of a run error is when the database is offline at run time and you try to access/access it, or when the code has semantic errors, such as the following program. It compiles normally, but you will only find out the problem when running it:

public class Program
{
    public static void main(String[] args) {
        // Chamada ao método.
        String notGonnaHappen = throwStackOverflowError();
    }

    public static String throwStackOverflowError() {
        // Recursão infinita que o compilador não tem capacidade de verificar.
        return throwStackOverflowError();
    }
}
 1
Author: Marcelo Shiniti Uchimura, 2020-08-07 18:14:28