An exception is an unexpected event that breaks the normal flow of program execution. It can handle by using try and catch blocks. In java exception has been categorized into two types as below.
- Checked Exception
- Unchecked Exception

Checked Exception
The exception which is can be identified at compile time it’s called checked exception. You should handle it otherwise you could not compile your program successfully. Below classes are child classes of Exception class and Exception class extends the Throwable class
- IOException
- SQLException
- ClassNotFoundException
Unchecked Exception
The exception which is can be identified at runtime, it’s called unchecked exception. Below classes are child classes of RuntimeException class. And RuntimeException class extends the Exception class
- NullPointerException
- ClassCastException
- NumberFormatException
- ArithmeticException
- IndexOutOfBoundsException
- ArrayIndexOutOfBoundsException
- StringIndexOutOfBoundsException
Error
An error also called unchecked exception, but you can not to handle it. Below classes are child classes of Error class. The Error class extends the Throwable class
- StackOverflowError
- OutOfMemoryError
- VirtualMachineError
Exception Handling
Exception handling in Java is the way to execute the program smoothly without any interruption.
If you have the program with 100 lines of code and if the exception occurred at the 40th line JVM can’t to execute the remaining code’s. To avoid this situation you should handle it.
Try: try is a block it has the codes which will be throw the exception.
Catch: catch is a block. Here you can handle the exception.
Finally: finally is a block. Here you can have the code which should execute even exception has been occurring or not.
try {
int value = 100/0;
System.out.println(value);
}catch(ArithmeticException e) {
System.out.println("Number can't to divide by zero");
}finally {
System.out.print("Completed");
}