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

Throws(Exception handling)  RSS feed

 
Jitendra Jha
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have read that we have to use 'throws' to warn callers to methods about a
checked exception which the method throws.and it is compulsory in such cases.What is bothering me that,why don't we provide a throws clause when we are calling the 'sleep(int i)' method which throws an InterruptedException.

Please help
 
Michael Lachenmaier
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure to understand your question.
Could you provide some code example to clarify your point of view?
 
Rachil Chandran
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You have to either catch an InterruptedException or declare throws while using Thread.sleep method.

If you do not want to catch and handle the exception in the method where you are using sleep, that particular methos has to declare a throws InterruptedException

i.e eihter


or

 
Campbell Ritchie
Marshal
Posts: 55715
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is another thread active at present about Exceptions here.

CR
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!