Java terminology: why a compile-time error and not an exception at compile time?

It may seem uncomfortable ...
But I did not understand this.

Why do we have a compile-time error and not a compile-time exception in java?

I want to say that we never say compile-time exception.
We tend to say this as a compile-time error .

Is there any specific reason for the same?
Any suggestions are welcome ....

Thanks!

+7
java exception exception-handling
source share
6 answers

The reason for this is that the exception is something that is thrown during program execution. Java has a specific type for this, the Exception class.

At compile time, your code is not executed, so it cannot throw an exception. In fact, it is the correct execution of the compiler to find errors in your code - of course, not an exception!

+10
source share

An exception in java is really different from a compilation error. We have no compile time exception. Since an exception happens, you do not expect this to happen. We excluded only a test and unchecked exception. With a checked exception, during compilation , the compiler will force you to catch it, but it is not an error . Do not understand, you cannot compile a program, but this is not a compilation error.

+4
source share

Mistake indicates a problem with the program. an exception is a particular construct that interrupts the program control flow and unwinds the stack, capturing information about the state of the stack so that it can be reported.

An exception can be used to indicate an error, but not always. For example:

 void startOperation() { try { while (someComplexOperationIsOnGoing()) { checkRestart(); } } catch (RestartException re) { startOperation(); } } void checkRestart() { if (shouldRestart()) { throw new RestartException(); } } 

This incomplete sample code is intended to show the case where the exception is not an error. This is not always best practice; but it is used in some cases where the goal is to interrupt the control flow deep into the program (for example, redirecting a page in the web infrastructure when responding to an HTTP request) and controlling the return to a higher level of the stack. The term exception refers to the mechanism that interrupts the program .

In java, there is an Exception class that encapsulates this behavior. The Error class also interrupts the control flow in the same way as the Exception; but it is reserved only for serious, fatal problems that occur at runtime. It is used, for example, when the JVM runs out of memory and cannot create new objects.

+3
source share

An exception is more than an unexpected thread that can be handled. A compile-time error is more like invalid code ... the code doesn't even compile. Consequently, the term β€œerror” as it denotes a more serious problem that needs to be fixed.

+2
source share

Compile-time errors are the result of the inability to create software as it is indicated. For example:

 String myString = new ButtonEvent(); 

- compile time error. Although the exception is what was discovered during the processing of the software.

 try{ while( file.readNextLine() != file.EOF ){ } } catch( UnopenedException ex ){ } 

Here we assumed that the file may have been opened correctly and was. The exception is for those "exceptional" cases when the file was not opened.

+1
source share

The exception is the specific error name that can be processed in the logic of your software. An error is just a typo or just the wrong code.

0
source share

All Articles