Example & Tutorial understanding programming in easy ways.

What is difference between Checked and Unchecked Exception in Java?

The difference between checked and unchecked exception are as follows:-

  1. Checked Exceptions should be handled in the code using try-catch block or else main() method should use throws keyword to let JRE know about these exception that might be thrown from the program. Unchecked Exceptions are not required to be handled in the program or to mention them in throws clause. 
  1. Exception is the super class of all checked exceptions whereas RuntimeException is the super class of all unchecked exceptions.
  1. Checked exceptions are error scenarios that are not caused by program, for example FileNotFoundException in reading a file that is not present, whereas Unchecked exceptions are mostly caused by poor programming, for example NullPointerException when invoking a method on an object reference without making sure that it’s not null.

 

Read More →