• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!