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

Answers were Sorted based on User's Feedback



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

Answer / vijay

CHECKED EXCEPTION IS TO BE HANDLED BY USE TRY AND CATCH
EXCEPTION....THAT HAS TO BE THROWN AND CATCH USEING THIS
EXCEPTION...WERE AS UNCHECKED EXCEPTION IS RUN TIME EXCEPTION.
THIS EXCEPTION IS NOT CHECKED AT THE TIME OF COMPILATION
HENCE IT CANNOT BE HANDLED WITH TRY AND CATCH.....

Is This Answer Correct ?    55 Yes 21 No

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

Answer / rakesh

A checked exception is one, which a block of code is likely
to throw, and represented by throws clause.It represents
invalid conditions in areas outside the immediate control of
the program (invalid user input, database problems, network
outages, absent files).
In Java it is expected that a method 'throws' an exception
which is a checked exception.They are subclasses of Exception.
While unchecked exceptions represent defects in the program
(often invalid arguments passed to a non-private method).
According to definition in The Java Programming Language, by
Gosling, Arnold, and Holmes,"Unchecked runtime exceptions
represent conditions that, generally speaking, reflect
errors in your program's logic and cannot be reasonably
recovered from at run time." They are subclasses of
RuntimeException, and are usually implemented using
IllegalArgumentException, NullPointerException, or
IllegalStateException
It is somewhat confusing, but note as well that
RuntimeException (unchecked) is itself a subclass of
Exception (checked)

Is This Answer Correct ?    31 Yes 6 No

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

Answer / 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

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

Answer / brahmi

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 ?    3 Yes 0 No

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

Answer / archana

What is the difference between Checked exceptions and
unchecked exceptions in JAVA?In: Java Programming [Edit
categories]
Computer Programming QuestionsAnswers.com > Wiki Answers >
Categories > Technology > Computers > Computer Programming
> Java Programming > What is the difference between Checked
exceptions and unchecked exceptions in JAVA?
Best Answer.
Unchecked exceptions :


•represent defects in the program (bugs) - often invalid
arguments passed to a non-private method. To quote from The
Java Programming Language, by Gosling, Arnold, and
Holmes : "Unchecked runtime exceptions represent conditions
that, generally speaking, reflect errors in your program's
logic and cannot be reasonably recovered from at run time."
•are subclasses of RuntimeException, and are usually
implemented using IllegalArgumentException,
NullPointerException, or IllegalStateException
•a method is not obliged to establish a policy for the
unchecked exceptions thrown by its implementation (and they
almost always do not do so)
Checked exceptions :


•represent invalid conditions in areas outside the
immediate control of the program (invalid user input,
database problems, network outages, absent files)
•are subclasses of Exception
•a method is obliged to establish a policy for all checked
exceptions thrown by its implementation (either pass the
checked exception further up the stack, or handle it
somehow)
It is somewhat confusing, but note as well that
RuntimeException (unchecked) is itself a subclass of
Exception (checked).

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More Swing Interview Questions

What is import javax swing jframe?

0 Answers  


What is swing in java with example?

0 Answers  


What is the purpose of transferhandler class?

0 Answers  


How is parsing html used in swing?

0 Answers  


What is JTable and what is its purpose?

4 Answers  






Why should the implementation of any swing callback (like a listener) execute quickly?

0 Answers  


What is swing and awt in java?

0 Answers  


What is import javax swing?

0 Answers  


Is swing thread-safe?

0 Answers  


What is difference between jframe and swing?

0 Answers  


How to print in java swing application?

0 Answers  


Why do we use swing in java?

0 Answers  


Categories