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
Can we override constructors in java?
What is the purpose of lambda expressions?
What are the 3 types of loops in java?
Explain the difference between intermediate and terminal operations in java8?
Explain the difference between arraylist and linkedlist in java?
Where is core java used?
Write a program to solve producer consumer problem in java?
What if I write static public void instead of public static void in java?
What is percentage in java?
Is an integer an object?
How we can run a jar file through command prompt in java?
What is the properties class in java programming?
What is the purpose of a transient variable?
How to display names of all components in a Container?
What is externalizable?