We know that, In java, Exception can be either checked or unchecked and same has been shown in the below exception hierarchy
Parent class of all exceptions in java is “Throwable” class.
Any instance of Throwable class can be caught using catch block except Error.
We can’t handle errors in Java through program.
Exception hierarchy mainly consists of Exception and Error
Where Error is something which we can’t handle programmatically but we can handle exceptions through program.
Any subclass of Exception can be handled programmatically in Java.
Throwable represent the super class of all exceptions and also Runtime Errors in Java.
Exception and its sub-classes represent unusual conditions in a program which is expected to occur but can recover from.
It has all the behaviours of checked exception.
Example : FileNotFoundException,SQLException
RuntimeException is a subclass of Exception
RuntimeException and its sub-classes represent unusual conditions in a program which is generally not expected to occur but can recover from.
It has all the behaviours of unchecked exception.
Example : NullPointerException,ArithmeticException
Error sub-classes represent “serious” errors that a program can’t catch and recover from.
Example : expected class file being missing, or an
Exception class acts as checked exception and its subclass RuntimeException class acts as Unchecked exception.
Checked exceptions are forced by compiler to handle whereas unchecked exceptions are not forced to handle but Its good to handle.