What is difference between Checked and Unchecked Exception in Java?
The difference between checked and
unchecked exception are as follows:-
- 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.
- Exception
is the super class of all checked exceptions whereas RuntimeException
is the super class of all unchecked exceptions.
- 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 →