What is the difference between Checked and Unchecked
exception? Give some examples
Answer Posted / narendra
checked Exceptions must be dealt with in either a try/catch
block or by
declaring a "throws" in a method. Unchecked exceptions
normally are
Runtime exceptions like NullPointerException or
ClassCastException.
A simple rule of thumb: If it's an exception you can
possibly deal with
(continue to run the program using some alternative code),
use checked
exceptions. For exceptions that should never happen (if they
do, it's a
bug), use unchecked (Runtime) exceptions which will come up
to the
surface and displayed to the user. Like this you assure that
if there's
a bug, it will show up eventually and can be fixed, and you
don't run
the risk of catching an exception and forgetting to deal
with it (f.i.
empty catch block).
| Is This Answer Correct ? | 4 Yes | 1 No |
Post New Answer View All Answers
What are the methods available in a class?
What are the uses of synchronized keyword?
What is the function of compareto in java?
Can an arraylist be empty?
How do you delete a list in java?
What is the technique adopted to create an immutable class?
What does indexof mean?
What is backdrop?
What are the differences between forwarding () method and sendredirect() methods?
Does java allow default arguments?
how to deploy apache tomcat server to weblogic server in java
Can we sort array in java?
Explain the significance of class loaders in bootstrap?
How do you sort a list in java?
What is the maximum size of array in java?