• 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
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

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: 74349
334
  • 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: 24203
44
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.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic