Win a copy of Zero to AI - A non-technical, hype-free guide to prospering in the AI era this week in the Artificial Intelligence and Machine Learning forum!
  • 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:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Catch or Throw a RuntimeException

 
Ranch Hand
Posts: 528
  • Mark post as helpful
  • send pies
  • 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
  • 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: 70612
288
  • Mark post as helpful
  • send pies
  • 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
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
Thank you very much . All are valid points.
 
reply
    Bookmark Topic Watch Topic
  • New Topic