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
How do you empty a list in java?
How do you define a method?
What is a flag variable?
What is the diffrence between inner class and nested class?
What is a memory leak in java?
What is method and methodology?
How many types of flags are there?
How is java created?
How do you check whether the list is empty or not in java?
Explain the difference between protected and default access.
Is java 9 released?
Why synchronization is important?
What is meant by oops concept in java?
Is main is a keyword?
What is the disadvantage of synchronization?