Introduction

Exceptions are the undesirable events during the execution of the program. Exceptions may stop the execution of the program. There are mainly two types of exceptions in Java, Checked Exceptions and Unchecked Exceptions.

Exceptions in Java

exceptions in java
In Java when an exception occurs, an exception object is created. This exception object contains all the details of the exception. Then a search is done for a relevant exception handler. If an exception handler is found then the exception is handled otherwise the program will stop executing.

Unchecked Exception

Checked Exceptions occur at the runtime of the program. These are also known as Runtime Exceptions. It is not a requirement to handle or catch them at compile time. These are mainly due to the mistakes in the program.
Examples Unchecked Exceptions

Checked Exceptions

Checked Exceptions occur at the compile time of the program. These exceptions should be either caught or handled during compile time. If we do not catch or handle them then the compiler will throw a compilation error. These are the sub classes of the Exception class.
Examples of Checked Exceptions
When to use Checked Exceptions
When to use Unchecked Exceptions

Difference between Checked and Unchecked Exception

Summary

This article explains Exceptions and their types in Java.