• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

exceptions

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the differance b/w checked and unchecked exceptions.how the JVM identifies these as checked and unchecked
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is more of a general Java question, so I'm moving it to the "Java in General (intermediate)" forum.
 
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic