This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
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

why sun people developed checked exceptions

 
sravani rendeddula
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why sun people developed some uncheched and some checked exceptions without making all exceptions as one type either checked or unchecked?
 
Rob Spoor
Sheriff
Pie
Posts: 20495
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Because some exceptions should be caught because they are caused by external sources (IOException, SQLException, RemoteException etc), while others can be prevented by enough checks (NullPointerException, IllegalArgumentException, ClassCastException etc). Forcing the latter to be caught would require a try-catch/finally block in each and severy method. Every line of code that involves calling a method can throw a NullPointerException.

If there would be no checked exceptions though, programmers could ignore them, providing no exception handling for these and see their programs crash horribly.
 
Campbell Ritchie
Sheriff
Posts: 48424
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to JavaRanch
A lots of unchecked exceptions actually represent mistakes in the code which have to be sorted by correcting the code. You need to find the Java Tutorials, which have all sorts of useful information in.
 
Garrett Rowe
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The checked vs. unchecked exceptions debate has caused many many religious war. The truth of the matter is that the Java creators took a stand on one side. Whether you believe it's the right side or not (and you're not alone if you don't) is irrelevant. When you code in Java you have to deal with these types of decisions. There are a number of other languages that also took a stand on the other side of the debate. I'm not sure there's a real right or wrong here, as with all things relating to engineering, there are trade offs, and personal preferences.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic