what is difference between checked and unchecked exception
plz explain examples ?

Answer Posted / shrikrishna kashid

Joined: Dec 13, 2007
Posts: 80
posted Friday, February 08, 2008 2:00 PM
Checked Exceptions:

A checked exception is any subclass of Exception (or
Exception itself), excluding class RuntimeException and its
subclasses.
You should compulsorily handle the checked exceptions in
your code, otherwise your code will not be compiled. i.e
you should put the code which may cause checked exception
in try block. "checked" means they will be checked at
compiletime itself.
There are two ways to handle checked exceptions. You may
declare the exception using a throws clause or you may use
the try..catch block.
The most perfect example of Checked Exceptions is
IOException which should be handled in your code
Compulsorily or else your Code will throw a Compilation
Error.

Unchecked Exceptions :

Unchecked exceptions are RuntimeException and any of its
subclasses. Class Error and its subclasses also are
unchecked.
Unchecked runtime exceptions represent conditions that,
generally speaking, reflect errors in your program's logic
and cannot be reasonably recovered from at run time.
With an unchecked exception, however, compiler doesn't
force client programmers either to catch the exception or
declare it in a throws clause.
The most Common examples are ArrayIndexOutOfBoundException,
NUllPointerException ,ClassCastException

Is This Answer Correct ?    19 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why swings are called lightweight components?

526


How to generate bill in java swing?

683


What is the use of double buffering in swings?

555


Explain the difference between awt and swt.

550


What is awt and swing in java?

498






What does javax swing do?

541


What is the base class for all swing components?

606


Explain the difference between swing and jsf.

614


What are the components of java swing?

526


Which method of the Component class is used to set the position and size of a component?

566


What are controls and what are different types of controls in awt?

527


What is swing api?

530


Which method is used by the applet to recognize the height and width?

652


What are heavyweight components? What is lightweight component?

530


What is the difference between invokeAndWait() and invokeLater()?

595