Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Use of Checked and Unchecked Exception

 
Naty wills
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a query regarding Exceptions in Java, as there are 2 types of exceptions in Java - Checked and Unchecked exceptions, but in other languages viz C++ there is only Unchecked exception. Can someone help me whats the advantage in using Checked and Unchecked exceptions. Why not there is not only Checked exceptions or Unchecked exceptions in Java? Why java supports both Checked and Unchecked exceptions?

Regards
Naty
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think as java has the concept of checked exceptions , it gives the developers more flexibility.

In case of checked exceptions , the flow gets a chance to retry some action and make the program continue further.
 
Raghavan Muthu
Ranch Hand
Posts: 3381
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes instead of leaving the decision to only the runtime environment, developer is also given a choice of how to and what to do further in case of any exception!
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Not really an advanced question. Moving...
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Checked exceptions give the compiler the chance to, well, check to see if they're being handled. The folks who invented Java thought this would requiere developers to acknowledge exceptions and help avoid surprising errors at run time. Many Java users appreciate the compile time help, but some resent the extra coding required to catch or declare throwing checked exceptions.

Bruce Eckel's Thinking In Java (free online) has a good chapter on exceptions that mentions the question whether checked exceptions are good or not.
 
Naty wills
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all of you :-)

Regards
~Naty
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic