What is Exception and Exception hierarchy in Java?
- Throwable class act as the root for Java Exception Hierarchy.
- A throwable class defines two child classes
- An unexpected unwanted even that disturbs normal flow of the program is called an exception.
- It is highly recommended to handle the exceptions and the main objective of exception handling is graceful termination of the program.Â
- Exception Handling doesn’t mean repairing an exception. We have to provide the alternative way to continue rest of the program normally is the concept of Exception handling.Â
- Most of the times exceptions are caused by our program and these are recoverable. For example, if our programming recruitment is to read data from remote file locating at Masco at runtime if remote file is not available then we will get runtime exception saying FileNotFoundException.
- If FileNotFoundException occurs we can provide local file and continue rest of the program normally.
- Most of the times errors are not caused by our program and these are due to lack of system resources.
- An error is non-recoverable.
- For example, OutOfMemoryError occurs being a programmer we can’t do anything and the program will be terminated abnormally.
- System admin or server admin is responsible to increase heap memory.
Exception Hierarchy Diagram