Java


Java Tutorial


Admission Enquiry Form

  




Different types of Errors in Java.

Before studying exception we must first know different types of errors:

  1. Syntax error or compile time error.
  2. Logical error.
  3. Runtime error.

Explanation

  1. Syntax error:The error which occurs at compile time when there is mistake in the syntax of code.

  2. Logical error: The error which the program compiles but the answer is not correct. This is due to some logical mistakes in the program.

  3. Runtime error: The error which occurs at runtime. The runtime error is known as exception.




What is Exception in Java?

The runtime error is known as Exception.Example: If you divide a number by zero the execution of the program stops working, at that moment we can say that an exception has occured.

Types of Exceptions:

Checked Exception

Checked Exception which is also called compile-time exceptions occurs at the compile time. If the method contains the code that throws an exception, the programmer must provide a mechanism to catch it in the same method. Examples of Checked Exceptions are: IOException, SQLException, etc.

Unchecked Exception

Java Unchecked Exception which is also called Runtime Exceptions occurs at runtime. This occurs during the execution of the program. Examples of Unchecked Exceptions are: ArithmeticException, ArrayIndexOutOfBoundsException, etc.

Some common examples of Exception are:

  1. Divide by zero errors
  2. Accessing the array elements beyond the range.
  3. Invalid input
  4. Hard disk crash
  5. Opening a non-existent file
  6. Heap memory exhausted