Error Hierarchy Exception In Details in Java Updated
In this article, we will discuss the exception hierarchy in detail with figure and explanation
Error Hierarchy In Java
The Throwable class is the root class for every exception and it branches out to 2 main categories i.e.;
- Exception
- Error
java.lang.Throwable
- Throwable is the root class for exception & it’s sub-type and error & it’s sub-types
- In other words, it is a superclass for exception & error
- java.lang.The throwable class extends java.lang.Object class (as shown in the above figure)
- It defines 2 subclasses i.e.; Exception and Error
java.lang.Exception
- java.lang.Exception is a superclass for all types of Exception
- It extends java.lang.Throwable class
- The exception is due to programmatic logic
- And it is recoverable
- An exception are categorized into a checked and unchecked exception
- Example: RuntimeException, SQLException, IOException, FileNotFoundException, ArithmeticException, NullPointerException
Check: ClassCast Exception
java.lang.Error
- java.lang.Error is a superclass for all types of Error
- It extends java.lang.Throwable class
- Error is due to lack of system resources
- And it is non-recoverable
- All error falls into unchecked exception category, as it is raised due to lack of system resources at runtime
- It is out of programming scope as such type of error can’t predict, maybe well-planned care can be taken to avoid this kind of Error
- Example: VirtualMachineError, AssertionError, ExceptionInInitializerError, StackOverflowError, OutOfMemoryError, LinkageError, InstantiationError
Note: the above-mentioned Exception and Error are again categorized into checked and unchecked exceptions
Leave a Reply