aspose file tools*
The moose likes Java in General and the fly likes Catch or Throw a RuntimeException Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Catch or Throw a RuntimeException " Watch "Catch or Throw a RuntimeException " New topic
Author

Catch or Throw a RuntimeException

RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
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 .


If you want something you never had do something which you had never done
Dawn Charangat
Ranch Hand

Joined: Apr 26, 2007
Posts: 249
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

Joined: Oct 13, 2005
Posts: 39791
    
  28
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

Joined: Jul 08, 2003
Posts: 24187
    
  34

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.


[Jess in Action][AskingGoodQuestions]
RaviNada Kiran
Ranch Hand

Joined: Jan 30, 2009
Posts: 528
Thank you very much . All are valid points.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Catch or Throw a RuntimeException