Difference Between Checked and Unchecked Exceptions in Java

In Java programming, for every occurrence of an exception, there generates an exception object, which holds all the details of the exception. Then the program searches for its respective exception handler. If found, the exception is handled or resolved or else the program execution stops.

Java generates two types of exception. These are:

  1. Checked exception
  2. Unchecked exception

Difference Between Checked and Unchecked Exceptions in Java

Checked ExceptionUnchecked Exception
Checked exceptions occur at compile time.Unchecked exceptions occur at runtime.
A checked exception is checked by the compiler.The compiler does not check these type of exception.
These types of exception can be handled at the time of compilation.These types of exceptions cannot be a catch or handle at the time of compilation, because they get generated by the mistakes in the program.
They are the sub-class of the exception class.They are runtime exceptions and hence are not a part of the Exception class.
Here, the JVM needs the exception to catch and handle.Here, the JVM does not require the exception to catch and handle.
Examples of Checked exceptions:
  • File Not Found Exception
  • No Such Field Exception
  • Interrupted Exception
  • No Such Method Exception
  • Class Not Found Exception
Examples of Unchecked Exceptions:
  • No Such Element Exception
  • Undeclared Throwable Exception
  • Empty Stack Exception
  • Arithmetic Exception
  • Null Pointer Exception
  • Array Index Out of Bounds Exception
  • Security Exception

Courses
Subscribe Updates via Email

Join 49,000+ W3schools lovers and get all the latest tutorials, programs, algorithms in your inbox.