io exception checked or unchecked code example

Example 1: What are checked Exceptions

1) All the subclasses of Throwable class except error,Runtime Exception and 
its subclasses are checked exceptions.
2) Checked exception should be thrown with keyword throws or should be provided 
try catch block, else the program would not compile. We do get compilation 
error.
Examples :
1) IOException,
2) SQlException,
3) FileNotFoundException,
4) InvocationTargetException,
5) CloneNotSupportedException
6) ClassNotFoundException
7) InstantiationException

Example 2: Can we use catch statement for checked exceptions

If there is no chance of raising an exception in our code then we can’t 
declare catch block for handling checked exceptions. This raises compile time 
error if we try to handle checked exceptions when there is no possibility 
of causing exception.

Tags:

Misc Example