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

What are the differences between string and stringbuffer?

585


What is classes in java?

515


Define how objects are stored in java?

559


Why hashcode is used in java?

497


What is complexity in java?

521






How do singleton patterns work?

513


How many wrapper classes are there in java?

532


What is the constructor?

579


What is identifier give example?

549


What is class forname used for?

538


How many bits are used to represent unicode, ascii, utf-16, and utf-8 characters in java programming?

553


Wha is the output from system.out.println(“hello”+null); ?

688


Is it possible to cast an int value into a byte variable? What would happen if the value of int is larger than byte?

542


What is ternary operator? Give an example.

595


Is it possible to define a method in java class but provide it’s implementation in the code of another language like c?

575