Hierarchy of Exceptions
Hierarchy of Exceptions
Throwable
------------------------------------------------------------------------
├── java.lang.Exception (Checked
Exceptions) │
│ ├── java.io.IOException
└── java.lang.Error (Serious Issues)
│ ├── java.sql.SQLException
├── java.lang.StackOverflowError
│ ├── java.lang.InterruptedException
├── java.lang.OutOfMemoryError
│ ├──
java.lang.ClassNotFoundException ├──
java.lang.VirtualMachineError
├── java.lang.AssertionError
├── ...
│
├── java.lang.RuntimeException
(Unchecked Exceptions)
│ ├──
java.lang.NullPointerException
│ ├──
java.lang.ArrayIndexOutOfBoundsException
│ ├──
java.lang.ArithmeticException
│ ├──
java.lang.NumberFormatException
│ ├──
java.lang.IllegalArgumentException
│ ├── ...
Explanation:
Throwable is the base class for both exceptions and errors.
checked Exceptions :-
Definition: These are exceptions that are checked at compile-time. The compiler
forces the programmer to handle them using try-catch or declare them using throws.
Unchecked Exceptions :-
Definition: These are exceptions that are not checked at compile-time. They occur
at runtime due to programming logic errors.