This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Exception chaining and handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Exception chaining and handling" Watch "Exception chaining and handling" New topic

Exception chaining and handling

Elena Taube

Joined: Dec 06, 2005
Posts: 21
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?


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

Joined: Jun 18, 2004
Posts: 28
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
I agree. Here's the link:
subject: Exception chaining and handling
jQuery in Action, 3rd edition