This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Exception chaining and handling

 
Elena Taube
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone,

I have never make in a practice the exception handling and i have no any experience with it. I have some questions about exception chaining and handling could you help me?



In this example I catch Exception1 and rethrow the Exception2. Since JDK 1.4 there is a possibility to add to the Exception2 a cause of the Exception1. But If I didn't throw the cause of the Exception1 is this also an exception chaining? Or the meaning of chaining is only if the cause (Throwable) of one exception will be thrown with the cause of another.

Another example. How is a best way to rethrow an exception in practice?

or



If I have e.g. three calls of different methods that catch one exception and rethrow the another one. Do I need to rethrow the cause of these exceptions every time and log at the end point all exceptions :

or just log the occurred exception before throwing and throw only the message?
How it will be made in a real applications?
Thanks a lot for your help!
 
C Broussard
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well what you're talking about is checked & unchecked exceptions.

unchecked exceptions should extend RuntimeException (they flow all the way up to the top of the stack unless you specifically catch it and do something w/ it) this is what the springframework uses.


checked exceptions are caught and handled with.

it is always preferred to do catch them and keep the original message

}catch(Exception e){
throw new BusinessLogicException(e);
}

... safe rule of thumb is to have business logic exceptions checked, and handled for whatever reason or however.. and system problems (sql, dataccess, etc unchecked).

hope that helps


www.binaryfrost.com
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic