• Post Reply Bookmark Topic Watch Topic
  • New Topic

regarding exceptions  RSS feed

 
manish ahuja
Ranch Hand
Posts: 312
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All

I do not know whether this would be the right thread to post this question but i could not get a better 1.

My question today is regarding exceptions.
We have to design some custom & business exceptions for a multi tier J2ee app.
We can either make these custom & busines exceptions extend RuntimeException class or the root Exception class.
I would like to know when should we go for making the custom exceptions extend RuntimeExcpetion or Exception.

Is it that if I want the custom exception to halt the current flow of the running program & the exception to be propogated straight back to calling client I should use the root Exception & say when i want the flow of the program to run uninterrupted & not to be stopped by a few minor exceptions I shuldmake them extend Runtime Exception

Kindly ellaborate on this with ur thoughts

Bye
Manish
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37469
539
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Manish,
Business exceptions should definitely not extend RuntimeException. These are things that you want to force the caller to handle, or at least acknowledge.

For the custom exceptions, consider whether the caller can do anything about it.
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
With a few minutes searching Google you'll be able to find many articles discussing the merits of using "checked exceptions" (those extending Exception) versus "unchecked exceptions" (those extending RuntimeException) using those terms.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rat on. You'll find it's a heated debate with strong voices for and against using unchecked exceptions. I used unchecked on one project as an experiment and found they were very well suited to the program structure. Other designs might work out very differently. I haven't chosen either style as "correct" for all future projects.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!