Java Types of Exceptions

There are three types of exceptions in java.

  • Checked Exception / Compile Time Exception
  • Unchecked Exception / Runtime Exception
  • Error
Java Types Of Exceptions
Java Types Of Exceptions

Checked, Unchecked, Error are raised only on Runtime. They never raised at compile time.

Checked Exceptions / Compile Time Exception

ThrowableException and all their sub classes (except RuntimeException, Error and their subclasses) put together are known as Checked Exceptions.

Checked Exception is an exception which is checked by the compiler during the compilation time and hence it is also called as Compile Time Exception

The Compiler follows “Handle Or Declare Rule” for the checked exceptions,  if a code throws compile time exception the compiler demand us to handle the exception with try-catch or declare the exception in the method using the throws keyword. Otherwise we will get compilation error. Let us try to understand with the following Example program.

Example : checked exception – checked by compiler – compilation error

Compilation Errors : error: unreported exception FileNotFoundException; must be caught or declared to be thrown
fis = new FileInputStream(“demo.txt”);
^ error: unreported exception IOException; must be caught or declared to be thrown
while ((c = != -1) {
^ error: unreported exception IOException; must be caught or declared to be thrown
3 errors

In the above example, We are reading the file demo.txt and displaying its content on the console. We got three compilation errors as we mentioned in the comments of the program. We can handle checked exception with try-catch block or declare the exception with throws keyword.

Some of the common checked exceptions are …

  • IOException
  • SQLException
  • FileNotFoundException
  • ClassNotFoundException
  • MalformedURLException
  • InvocationTargetException
  • ParseException
  • InterruptedException 
  • MalformedURLException

Unchecked Exception / Runtime Exception

RuntimeException and all its sub classes put together are known as Unchecked Exceptions.

Unchecked Exception is an exception which is not checked by the compiler hence it is also called as Runtime Exception

 If your program is throwing an unchecked exception, Even if you didn’t handle/declare that exception, the program won’t give compilation error.

Example : unchecked exception – not checked by compiler – no compilation error

Output :

main begin
Exception in thread “main” java.lang.ArithmeticException: / by zero
at com.vidvaan.corejava.exception13.typesOfExceptions.UncheckedExceptionExample.main(

In the above example, We are not getting any compilation error even there is a chance of getting unchecked ArithmenticException. So It clear that unchecked exceptions are not checked by the compiler. We can handle unchecked exceptions with try-catch or pre-conditions.

Some of the common unchecked exceptions are …

  • NullPointerException
  • ArithmeticException
  • NumberFormatException
  • ArrayIndexOutOfBoundsException
  • StringIndexOutOfBoundsException
  • IllegalArgumentException
  • IllegalStateException
  • ClassCastException 


Error and all its sub classes put together are known as Errors. Errors are irrecoverable problems. Errors occur due to lack of system resources like Memory Issues. We never handle and can’t handle and never catch Errors. If Errors are raised in the application execution it will simply get terminated.

Errors also comes under unchecked exceptions, But Errors represents irrecoverable problems. Let’s see an example of Error below which leads StackOverFlowError.

Example : Error – irrecoverable problem

We can handle Errors by upgrading system resources as per application requirement. But we can’t avoid termination of the application when Errors raised.

Example Errors are shown below.

  • OutOfMemoryError
  • VirtualMachineError
  • AssertionError
  • IOError 
  • AnnotationFormatError
  • StackOverFlowError
Scroll to Top