This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Java in General and the fly likes exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "exceptions" Watch "exceptions" New topic
Author

exceptions

rayal singam
Greenhorn

Joined: Apr 10, 2006
Posts: 3
what is the differance b/w checked and unchecked exceptions.how the JVM identifies these as checked and unchecked
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42364
    
  64
This is more of a general Java question, so I'm moving it to the "Java in General (intermediate)" forum.


Ping & DNS - my free Android networking tools app
Rodrigo Alvarez
Ranch Hand

Joined: Apr 10, 2006
Posts: 75
what is the differance b/w checked and unchecked exceptions.


If a piece of code potentialy throws a checked exception, the compiler forces you to surround it with a try/catch or to declare that your method throws this exception. It does not if it is an unchecked exception (=> a method never has to declare that it can throw an unchecked exception)

how the JVM identifies these as checked and unchecked


Any exception inheriting from RuntimeException in unckeched, all the others are checked.

Note: unchecked exceptions must be considered as bugs: i.e. something that is not planned as opposed to checked exception which represent an unexpected state of things (like a connection closed by a 3rd party).

It is considered a bad practice to throw an unchecked exception: use something that the client class must catch deal with.

It is considered a bad practice to catch an unchecked exception: suppress the root cause in development time rather than dealing with it in runtime: remmember that (in a perfect world) unchecked exceptions must considered as bugs.


It is a mistake to think you can solve any major problems just with potatoes.<br />--Douglas Adams
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Be aware that plenty of folks disagree with Simon.

The very existence of checked exceptions is controversial. Many languages don't have them and seem to get along just fine. A signficant number of bright people recommend using unchecked exceptions exclusively. Google around for more on the debate.

Bruce Eckell covers the subject with fair attention to both sides in Thinking In Java. His own suggestions matured (completely changed) from the first to third editions. Anybody know what he says in 4th edition?


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: exceptions