checked exception 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: what do you do with checked exception

I would either handle or declare. I Declare using THROWS keyword or handle by
using TRY&CATCH block. If I will use it again I would handle it. If it will
occur only once than I would use THROWS keyword

Example 3: 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