• 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

Catch or Throw a RuntimeException

 
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question is only for Knowledge Transfer.

Will it be ever feasible to catch or throw an RuntimeException ? Will there be any such requirements in a Web based or a Desktop Application .


Thanks in advance .
 
Ranch Hand
Posts: 249
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can, and mostly will, catch runtime exceptions [FileNotFounds.... NUllPointers etc].... but no, no throwing them back. You need to catch a runtime exception, and convert it to an app specific exception and rethrow if required.
Having said that - dont ever catch or throw an Error.
and yes, the catching and throwing is generic to applications... it doesnt matter if you are dealing with desktop apps or web apps.

Dawn.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes,m you can always catch or throw a RuntimeException.
Whether it is worthwhile is another matter; similar discussion came up a few months ago, here.
 
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
People throw RuntimeExceptions all the time. It's a handy way to report a problem without forcing the immediate caller of a routine to handle an exception. Of course somewhere the exception has to be handled, but this might be in a top-level command dispatcher or somewhere else central to the application.

You can -- and generally should -- catch RuntimeExceptions somewhere in a nontrivial application. Again, often this is at a fairly high level. But as the alternative to catching them is letting the application terminate, it's often best to catch them in larger applications so that you can do cleanup tasks, etc.
 
RaviNada Kiran
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much . All are valid points.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic