DEV Community

Dharshini E
Dharshini E

Posted on

Types of Error in Java

Types of Error in Java:

  • Syntax Errors (Compile-Time Errors)
  • Runtime Errors (Exceptions and Errors)
  • Logical Errors

1.Syntax Errors (Compile-Time Errors):

Compile Time Errors are those errors which prevent the code from running because of an incorrect syntax such as a** missing semicolon** at the end of a statement or a missing bracket, class not found, etc. These errors are detected by the java compiler and an error message is displayed on the screen while compiling. Compile Time Errors are sometimes also referred to as Syntax errors .

2.Runtime Errors (Exceptions and Errors):

  • Run Time errors occur or are detected during the execution of the program. Sometimes these are discovered when the user enters an invalid data or data which is not relevant .
  • During compilation, the compiler has no technique to detect these kinds of errors. It is the JVM (Java Virtual Machine) that detects it while the program is running. To handle the error during the run time we can put our error code inside the try block **and catch the error inside the **catch block .

3.Logical Error:

A logic error is when your program compiles and executes , but does the wrong thing or returns an incorrect result or no output when it should be returning an output. These errors are detected neither by the compiler nor by JVM.

Top comments (0)