5
A build error would be the one the IDE already warns about even before compiling, such as missing a semicolon, correct? But what about the error of execution? It would be for example a Exception
?
5
A build error would be the one the IDE already warns about even before compiling, such as missing a semicolon, correct? But what about the error of execution? It would be for example a Exception
?
7
The overall answer has already been given in What’s 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 getting to runtime. But there are several cases where this is impossible. There are situations that you only know the error occurred at the time it is occurring, there is no way to anticipate that it will occur or potentially 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 to get to it went through several steps 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. They are operating errors outside the 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 it go wrong. The division by 0 is one of them. Arguments passed to functions are other, index a data collection outside the range 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 launching 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 launched. This may even be something that comes externally informed and even from the processor.
Whenever an exception is released we can say that there was an error. Java has the culture of handling even invalid data as an error, which for many is a misconception, is using exception for something not exceptional.
Any error that can be detected at compile time should be. Code lexical, syntax and semantic errors can be detected at this time.
Technically there is no way to report an 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.
1
That’s right.
Build error: when an invalid or wrong syntax character is found in the code.
Execution error: After the code is compiled, when running the project, one finds some sql Exception, casting, some calculation error, etc. That is, the execution error would be a logical error and not a "grammar" error let’s say.
1
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 the one that, as the name says, only happens when the executable or library is run/run.
An example of an execution error is when the database is offline at the time of execution 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 discover 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();
}
}
Browser other questions tagged java exception compilation runtime
You are not signed in. Login or sign up in order to post.