Exception Handling-


Exception is an abnormal condition which is interrupt normal flow of program. 

Exception is a class coming from java.lang package, And Throwable is a immediate parent class of Exception. 

 

In Java 2 types of Exception 

A.       Checked [Compile Time] Exception- 

  1. Those exceptions that are checked at compile-time also known as checked exceptions. 
  2. The program will not compile if they are not handled. 
  3. They are child classes of Exception except for RuntimeException. 

 

Example: IOException, SQLException, etc. 

B.       Unchecked [Run Time] Exception- 

  1. Those exceptions that are checked at runtime also known as unchecked exceptions. 
  2. They give runtime errors if not handled explicitly. 
  3. They are child classes of RuntimeException. 

 

Example: ArithmeticException, NullPointerException, etc. 

 

There are 5 blocks for Exception Handling- 

  1. Try- Exceptional code will add in try block 
  2. Catch- It is used for catch the Exception 
  3. Throw- It is user defined Exception 
  4. Throws- It is system generated Exception 
  5. Finally- It always execute