Checked and Unchecked Exception

Author posted by Jitendra on Posted on under category Categories JAVA and tagged as Tags with 1 Comment on Checked and Unchecked Exception

Explains the concept of checked exception and unchecked exception in JAVA.

There are two types of exception available in java:

  1. Checked exception
  2. Unchecked exception

Checked exception:

  1. Checked exception represents the invalid condition is program and must be declared by using keyword throws in method.
  2. checked exception extends java.lang.Exception class.
  3. IOException, ClassNotFoundException, SAXException are the well known examples of checked exception.


public void setDate() throws ShivaSoftException
   if(dateOfBirth < todaysDate)
        throw new ShivaSoftException("Date of birth cannot be in future");

checked exception forces the calling method to be enclosed in try catch block.

Unchecked Exception:

  1. Unchecked exception represents the defect in programming logic and occurs at runtime. it does not forces the code to be enclosed in try catch block.
  2. Unchecked Exception extends java.lang.RuntimeException class.
  3. ArithmaticException, NullPointerExceptionIndexOutOfBoundsException are well known examples of Unchecked Exception.


public void errorMethod()

The above method will give the ArithematicException at runtime but did not force to be enclosed during compile time.

Related posts

One thought on “Checked and Unchecked Exception”

Leave a Reply