Exception handling in java???
before describing technical definition, first of all elaborate what is exception?
Exception stands an event that disrupts the normal flow of the program. It is an object which is thrown at run time.
Technical definition it is an mechanism to handle runtime errors such as classnotfound, SQL, remote etc.
Core Advantage of Exception Handling:
It is to maintain the normal flow of the application. Exception normally disrupts the normal flow of the application that is why we use exception handling.
Let's take an e.g.
- statement 1;
- statement 2;
- statement 3;
- statement 4;
- statement 5;
- statement 6;
- statement 7;
- statement 8;
- statement 9;
- statement 10;
Suppose there is 10 statements in your program and there occurs an exception at statement 5, rest of the code will not be executed i.e. statement 6 to 10 will not run. If we perform exception handling, rest of the statement will be executed. That is why we use exception handling in java.
TYPES OF EXCEPTION:
There are mainly two types of exceptions: checked and unchecked where error is considered as unchecked exception. The sun microsystem says there are three types of exceptions: