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 is a local class in java?
What is a constructor overloading in java?
Mention the default values of all the elements of an array defined as an instance variable.
What is difference between static class and singleton pattern?
Do we need to manually write Copy Constructor?
Which is easier .net or java?
What is the new line character?
please send me hr interview questions in it industry
What is a prefix function.write down a code to compute prefix function.
Is string is a data type?
What is qms certification?
Can we synchronize static methods in java?
What is diamond operator in java?
What is keyset in java?
What is supplier in java?