Exception in Java (2) - Checked|Unchecked Exception

Basically, there are two types of Exception, Checked Exception and Unchecked Exception.

Checked Exception occurs during the compile time. So, we can called that it is compile time exceptions.

It should handle the exception using try-catch block or it should declare the exception using throws keyword, otherwise the program will give a compilation error.

Example of Checked Exceptions are :

  • IOException

  • ClassNotFoundException

Unchecked Exception occurs during the execution time, so that we can call Runtime Exceptions.

It won't give a compile error even you didn't handle or declare the exception during the execution time.

Example of Unchecked Exceptions are :

  • NullPointerException

  • ArrayIndexOutOfBoundsException

  • ArithmeticException

Most of the developer add error handling for Unchecked Exception.

0