• Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception concept clarification -help!  RSS feed

 
Ranch Hand
Posts: 232
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If there is a throws statement with a method A, then must the calling method of method A have a ty-catch block, OR a throws statement to avoid a compiler error ???
thanks
 
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i think either would work..you can either catch the exception there or pass it up
manav
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sarim,
Any method that can cause a checked exception, can either use the try block and catch the exception in a handler, or it can explicitly propagate the exception to its caller by using the throws clause in the method header.
This ensures that, regardless of the path of execution, checked exception will be monitered.
 
Ranch Hand
Posts: 208
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I would like to add an interesting point --- in the case of unchecked exceptions or runtime exceptions
1. You need not throw them.
2. If you throw them, you can choose to catch or not to do so, your code will still compile fine.
3. You can give the throw < ....> within the method and even forget to give the throws clause in the method definition.
------------------
Regards,
Shree
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!