Java Exceptions Hierarchy
In Java, exceptions are objects, when you throw an exception, you are throwing an object. You can’t throw just any object as an exception as Exceptions needs to be in the inheritance hierarchy of Throwable. Throwable is the base class for the Exceptions.
The Hierarchy is like below. Throwable is the base class. Error and Exceptions are extended from the Throwable.
The below shows the hierarchy of the java exception.
Throwable
———————
| |
Error Exception
What is Exception?
The Exception is a way to handle the abnormal condition in Java. Exceptions are abnormal conditions and are recoverable. For example, say, a method is expecting a String object based on some condition. Now, the passed parameter is a List object. It is a abnormal condition and we throw need to throw back an exception saying, it is not a valid parameter. I would throw an IllegalArgumentException.
What is Error?
Errors are system errors. When there is an abnormal condition in the Java Virtual Machine, then the system throws the Error. Errors are more likely non-recoverable ones unlike the Exceptions. For example, Out of memory is an error. In this case, the system will not be able to recover as there is no memory to proceed.
Did you enjoy this post? Why not leave a comment below and continue the conversation, or subscribe to my feed and get articles like this delivered automatically to your feed reader.

Comments
No comments yet.
Leave a comment