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


Please Help Members By Posting Answers For Below Questions

How to sort list of list in java?

894


How do you trim a space in java?

746


What is a text string?

883


Does list maintain insertion order java?

726


Is logger a singleton?

743


What are the advantages of assembly language?

722


What is the default size of arraylist in java?

771


What is break and continue statement?

819


How do you represent a space in regex java?

761


What is the difference between the size and capacity of a vector?

814


What is a Hash Table? What are the advantages of using a hash table?

875


What does nullpointerexception mean?

881


why Interface used?

765


Where is singleton pattern used?

777


Why string objects are immutable in java?

823