• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

RuntimeException Handling

 
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi.......
why client cannot do anything to throw(or recover from exception) a RuntimeException or create a subclass of RuntimeException.?Suppose a programmer may be tempted to write code(or class) that throws only unchecked exceptions or to make all their exception subclasses inherit from RuntimeException,so what happens if some other programmers using this class, and it is so good to document a method's API, including the exception it can thrown, why not specify runtime exception too?
 
Ranch Hand
Posts: 5575
Eclipse IDE Windows XP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

raj chiru wrote:
why client cannot do anything to throw(or recover from exception) a RuntimeException or create a subclass of RuntimeException.?



I cant understand the *client* . but programmer can create the RuntimeException
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most of the assumptions you've made here are wrong:

(1) You can extend RuntimeException
(3) You can throw RuntimeExceptions
(3) You can catch RuntimeExceptions
(4) You can declare them in your method signature

But catching them and declaring them is optional. I would agree that if an API is designed so that it deliberately throws RuntimeExceptions only, then they should be documented.

 
Quick! Before anybody notices! Cover it up with this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic