Exception is an event/error than can happen during the execution (i.e. run time) of a program which disrupts the normal flow of program.
Put Exception hierarchy image here
Exception Hierarchy
- Throwable is the parent class of Exception Hierarchy and it has 2 children Error and Exception. Exception is further divided into Checked Exceptionand RunTimeException
- Errors: These are the scenarios that are not in the scope of application to handle hence not possible to anticipate and recover from them. e.g. Hardware failure, JVM crash, OutOfMemory, etc.
- Checked Exception: These exceptions are scenarios that we can anticipate in a program and try to recover from it. They are checked at compile time. e.g. IOException, FileNotFoundException, etc.
- RuntimeException: Usually Runtime Exception occur due to programming error. It is also called UnChecked Exception because it is not checked at compile time at e.g. trying to access invalid index of array, etc.