Exception Handling in Java

In Java Exception handling is defined as to handle the runtime expection to maintain the normal flow of application.

What is exception

Exception is simply defined as the events that distrupts the normal flow of the application that is called exception.

Advantage of Exception Handling

The main advantage of exception handling is that it is maintain the normal flow of the application.

for example

If there is 10 Statements if error occured on statement 5 than rest statement 6 to 10 will not run. But by the using of exception handling rest of the statement executed.

1.	statement 1;  
2.	statement 2;  
3.	statement 3;  
4.	statement 4;  
5.	statement 5;//exception occurs  
6.	statement 6; 
7.	statement 7; 
8.	statement 8; 
9.	statement 9; 
10.	statement 10;

Types of Exception

Exception is three types in java.

1.Checked Exception

This type of exception can be easily predicted by the programmer during compile time of application.Example : File that need to be opened is not found.

2.Unchecked Exception

This type of error ignored at compile time but occurs during Runtime. Example : ArithmeticException, NullPointerException, Array Index out of Bound exception.

3.Error

Error is unpredictable it can occured either runtime or compile time.

Uncaught Exceptions

class UncaughtException
{
 public static void main(String args[])
 {
  int a = 0;
  int b = 5/a;     // Divide by zero, will lead to exception
 }
}