Checked Exception vs Unchecked Exception - rahul00773/JavaConcepts GitHub Wiki

The exceptions which are checked by the compiler for smooth execution of the program are called checked exceptions.

Example: HallTicketMissingException,PenNotWorkingException,FileNotFoundException etc.

In our program, if there is a chance of raising checked exceptions then compulsory we should handle the checked exception. (Either by try-catch or by throws keyword). Otherwise, we will get a compile-time error.

The exceptions are not checked by the compiler whether programmer handling or not. Such types of exceptions is called unchecked exceptions.

Example: ArthmeticException, NullPointerException etc.

Note: Whether it is checked or unchecked every exception occurs at runtime only. There is no chance of occurring any exception at compile time. Runtime Exception and its child classes, Error, and its child classes are unchecked. except these remaining are checked.

Fully Checked Vs Partially Checked

A checked exception is said to be fully checked if and only if all its child classes also checked. Example: IOException, IntereptedException

A checked exception is said to be partially checked if and only if some of its child classes are unchecked. Example: Exception, Throwable,

Note: The only possible partial checked exception in java is Exception and Throwable.

Describe the behaviour of the following exceptions:

  1. IOException (Fully Checked)
  2. RunTimeException (Unchecked)
  3. InterruptedException (Fully Checked)
  4. Error (Unchecked)
  5. Throwable (Partial Checked)
  6. ArthmeticException (Unchecked)
  7. NullPointerException (Unchecked)
  8. Exception (Partial Checked)
  9. FileNotFoundException (Fully Checked)