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 is abstract class constructor called?

797


Explain thread in java?

877


What is increment in java?

735


What is :: operator in java?

710


What is compareto () in java?

725


In a program, initializing an array of 100 KB is throwing an out of memory exception while there is 100 MB of memory available. Why?

782


Can we define a package statement after the import statement in java?

826


What is definition and declaration?

747


What are the two types of java programming?

763


Can we have more than one package statement in the source file?

868


Define an applet in java?

843


What is the use of bufferedreader?

761


What is the java virtual machine?

856


What is the difference between public, private, protected, and friend access?

794


What are wrapper classes in java?

805