Types of Exception..
There are mainly two types of exceptions: checked and unchecked where error is considered as unchecked exception. The sun Microsystems says there are three types of exceptions:
- Checked Exception
- Unchecked Exception
- The Exceptions which are checked by the compiler for smooth execution of the program at run time are called Checked Exceptions.
FileNotFoundException, IOException, SQLException
- In the case of Checked Exceptions, the compiler will check whether we are handling exception if the programmer not handling then we will get compile time error.
Let's see an example for better clarity.
public static void main(String args)
PrintWriter pw=new PrintWriter("f.txt");
unreported exception FileNotFoundException; must be caught
or declared to be thrown
Here when we are compiling this program, the compiler generated a report which represents that there may be a chance FileNotFoundException arises at run time if the welcome.txt file is not found. So in this way the compiler gave this message to the programmer. This is known as checked exception.
- The exceptions which are not checked by compiler are called as unchecked exceptions.
ArithmeticException, NullPointerException, ArrayIndexOutOfBoundsException etc.
- In the case of unchecked exceptions, the compiler wont check whether programmer handling exceptions or not.
- Whether the exception is Checked or Unchecked, compulsory it will occur only at run time. There is no chance of occurring any exception at compile time..
- Runtime exception and its child classes, Error and its child classes are Unchecked except this remaining are Checked exceptions.
- Most of the times errors are not caused by the programs, these are due to system lack of resources.
- Errors are non recoverable.
- If OutOfMemory error occurs being a programmer we can’t do anything and the program will be terminated abnormally.
- System admin or Server admin is responsible to increase heap memory.