Java Programming
About Lesson

Types of Exceptions
There are two types of Exceptions, they are
Checked exceptions: All sub classes of Exception class except RunTimeException and Error class of Throwable class are Checked Exceptions
Unchecked exceptions: Runtime exceptions under Exception class and Error class of Throwable class are Unchecked Exceptions.

Difference between Checked and Unchecked Exceptions
Checked exception will be taken care by the compiler by warning or suggesting you to handle it while unchecked exceptions are ignored by the compiler.
In the case of Checked exceptions your program is connected to external resource while in the case of Unchecked exceptions your program is not connected to any external resource.
Examples of Checked Exceptions: SQLException, IOException, FileNotFoundException, InterruptedException
Examples of Unchecked Exceptions: ArithmeticException, ArrayOutofBoundException

//Example code for Checked Exception
public static void main(String[] args) {
PrintWriter x=new PrintWriter(“best.txt”);
x.println(“Hello”);
}
Above code gives a compile time error as Unhandled FileNotFoundException

The checked Exceptions are two types:
Partially checked
Fully Checked

Difference between partially vs fully checked exceptions:
Partially checked exceptions are the Checked exceptions where parent level exceptions are checked while child level classes are unchecked. The only two partially checked exceptions are Throwable and Exception
Fully checked exceptions are checked exceptions at both parent as well as child level. Except above mentioned two partially checked exceptions, all the remaining checked exceptions are fully checked.
There is no further category for unchecked exceptions like partial or full.

Manual Exception handling
It is not recommended to delegate the job of handling exceptions to the JVM since it causes abnormal termination of the program. Abnormal termination may result data loss or blockage of resources. Hence, java provides try…catch mechanism to handle exceptions manually by the developer.

You cannot copy content of this page