Checked vs UnChecked Exceptions in Java


There are 2 types of Exceptions:

1. Checked Exception(checked by the compiler at the time of compilation )
a. Checked Exceptions are occurred at the compilation time.
b. Checked Exception is a reminder by compiler to programmer to handle failure scenario.
c. The programmer should fix the Checked Exceptions by using throws keyword or surrounded by try-catch block.
d. Examples of Checked Exceptions given by JAVA API:
     IOException
     SQLException
     DataAccessException
     ClassNotFoundException
     InvocationTargetException, etc.

e. All checked exceptions must extends Exception class

2. Unchecked Exception( checked by the JVM at runtime)
a. Unchecked Exception occurs during the execution of a program.
b. Unchecked Exceptions are direct sub Class of RuntimeException.
c. Examples of Unchecked Exceptions given by JAVA API :
      NullPointerException
      ArrayIndexOutOfBound
      IllegalArgumentException
      IllegalStateException etc.

Search This Blog

All the rights are reserved to this blog is belongs to me only.. Powered by Blogger.