Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Could someone give me some information on this question?  RSS feed

 
kenny gill
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Not to sure how to answer this and would like some advice:

Why are unchecked exceptions harder to find than checked exceptions?
 
Campbell Ritchie
Marshal
Posts: 55748
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There’s nothing like a specific question and that was nothing like a specific question!
What makes you think unchecked Exceptions are harder to find? Whenever you write code which you expect to suffer an error, you can declare a checked ExceptionNow the javadoc will show that it declares such an Exception, even if you don’t (as you should) use the /**...@throws */ tag
Now, if you suffer a RuntimeException, you might not anticipate it.That method will throw an Exception if you pass 123, 0 to it, but you might forget. Actually in my experience, unchecked Exceptions are commoner than checked Exceptions, and I have never suffered real nasties like IOException itself.
That quotient method should probably be rewritten like this.Note you only put the unchecked Exception in the javadoc, not in a throws clause, so it is less easy to find in the API documentation.

I think I might have give you your answer
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!