aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Chained Exceptions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Chained Exceptions" Watch "Chained Exceptions" New topic
Author

Chained Exceptions

Steve Granton
Ranch Hand

Joined: Jan 13, 2002
Posts: 200
Hi,
I was considering using chained exceptions in my project as described atJavaWorld
Rather than reinvent the wheel I was planning to use the code provided there and give the author credit in the documentation.
Would I loose marks for this? Has anyone else used chained exceptions?
Cheers,
Steve
Robin Underwood
Ranch Hand

Joined: May 01, 2002
Posts: 117
I based my code on exactly the same article, but added chaining to DatabaseException. I didn't give the author credit, maybe I should have. I think that using chaining really improved my exception handling code.
I think that chaining is automatically included in JDK 1.4 (I'm using 1.2.2).
Don't know whether it hurts the grade since I haven't uploaded mine yet. I've got to get it out the door since the essay test is on Saturday!
Gosling Gong
Ranch Hand

Joined: Jun 20, 2002
Posts: 51
Hello, guys!
could you tell how you organize your exception handling, I am really frustrated on this issue. taken an example, in my bookFlight() in data facade, I do
try{
...
}catch(..){
}finally{
unlock();
}
but unlock is also throwing exception, then I have to try it in the finally, which I think is really mess.
where do you throw client specific exception, and where should throw the original specific exception?
Robin Underwood
Ranch Hand

Joined: May 01, 2002
Posts: 117

The link to the Java World article above has links to several really good exception handling articles.
Gosling Gong
Ranch Hand

Joined: Jun 20, 2002
Posts: 51
I readed all the three articles, but I still can not clear my head. I can't apply the guideline into practical use.
in the case of this assignment, to throws GUI interested exception, should we have to create a new DataAccessProxy which will handle all the Exceptions throwed by Data and rethrow a new specific Exception, or can we do it in the DataFacade?
by the way, how do you think about the exception handling in bookFlight method in the last post. don't you throw exception in unlock()?
thanks!
Robin Underwood
Ranch Hand

Joined: May 01, 2002
Posts: 117

I also have unlock in the finally clause wrapped in a try/catch. I ignore any exception on the unlock so it won't mask the original exception.

In my DataClient (which I think is the same as your DataFacade) I caught IOExceptions, including RemoteExceptions, and rethrew them as DatabaseExceptions. DataClient also changed the message wording to something more user-friendly.
Gosling Gong
Ranch Hand

Joined: Jun 20, 2002
Posts: 51
Originally posted by Robin Underwood:
I ignore any exception on the unlock so it won't mask the original exception.

Thanks, Robin!
so, in your datainterface, you don't let the unlock throw any exception?
I am thinking it will be at least throwing RemoteException when in network mode. but your DataClient doesn't know what mode it is now, so in your DataClient, how did you make it not handling the Exception?
Robin Underwood
Ranch Hand

Joined: May 01, 2002
Posts: 117
My DataInterface throws IOException and DatabaseException for every method.
For the unlock in the finally clause, catch the exception but don't throw another exception.
Amit Kr Kumar
Ranch Hand

Joined: Feb 08, 2002
Posts: 100
Hi Robin, Mark and others
This article also explains that exception and other messages should be seperate from GUI. The MessageFormat class and Resource Bundles can be used to have all the exception messages at one place.
Its not only useful for internalization / Locales
(which is not required here) but also for better maintainability and design. Also reuse of messages
is possible.
My question is that is it overkill to use this feature in this assignment or we should implement it here ?
Has everybody harcoded the messages (e.g. Network error, Pls try again or contact administrator) etc for RemoteExceptions) in GUIs / Controllers. Or they have defined at one place and used them in GUI whenever required as per this article.
Amit
Robin Underwood
Ranch Hand

Joined: May 01, 2002
Posts: 117
My messages are hardcoded, but it sounds like a good idea to have them in one location. I don't know if you'd get any credit for this. Sun's Data class has them hardcoded, so you probably wouldn't you wrong with that approach.
Amit Kr Kumar
Ranch Hand

Joined: Feb 08, 2002
Posts: 100
Thanks Robin
What about others, How they have implemented messages in their GUI and exceptions ???

Robin, did u created a ChainedException class that extend exception and made your DatabaseException class extend this ChainedException ??
Amit
Robin Underwood
Ranch Hand

Joined: May 01, 2002
Posts: 117
I just put the chaining code in DatabaseException, but I think it would be better to have DatabaseException extend from ChainedException.
BJ Grau
Ranch Hand

Joined: Jul 10, 2001
Posts: 234
I just hard coded my exception messages. There are so many things in this project that could be done a better way, but then it would never end.
 
 
subject: Chained Exceptions