• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Catch or Throw a RuntimeException

 
RaviNada Kiran
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 .
 
Dawn Charangat
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.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49472
64
  • 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.
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • 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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic