• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Chained Exceptions

 
Steve Granton
Ranch Hand
Posts: 200
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The link to the Java World article above has links to several really good exception handling articles.
 
Gosling Gong
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 100
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 117
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 234
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic