Exception handling is one of the important task for every programmer. For a successful project completion, proper exception handling is important. Exception is an abnormal error encountered by program which is not anticipated by the program, but it is the responsibility of a developer to gracefully handle the exceptions and redirect with suitable error message for the user or try the alternative solution by looking at the reason for the exception.
In Java, exception is derived from the root class Throwable. Look at the overview of the hierarchy for the exceptions.
The Throwable class is the super class of all errors and exceptions in the Java language. Only objects that are instances of this class (or one of its sub classes) are thrown by the Java Virtual Machine or can be thrown by the Java throw statement. All the exceptions are sub class of java.lang.Exception class.
Logically, exceptions can be classified into three categories.
- Checked Exception
- To describe briefly Checked exceptions are those, which you are required to treat. It is with a try-catch block or a throws (releasing the same to another location). On the other hand, when you have the type Unchecked exceptions, then it need not be treated, you can treat only if you want or feel that it is necessary for the proper operation of your application.
- Uu-checked Exception
- Unchecked exceptions are used for unrecoverable errors. This means that when you know that your error can be treated, you can use Checked Exceptions, otherwise use Unchecked Exceptions.
- Errors are fatal error which can not be handled and system will be down. This normally happens when problem arises which is not in the application like server crash, out of memory error, etc. which all abruptly shut down the application.