This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

About Exception.

 
Paul Sun
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello:
It is my first time to come here. Now I am doing
the assignment. I am confused about Exception.In my program, for example, client object throw
an exception when it fail to connect to server,
a controller object will catch it and throw nothing but send error type to client, client
will popup a message depend on the error type.
Am I right? Could someone tell me their experience
about chained Exception?
Thanks.
 
Nate Johnson
Ranch Hand
Posts: 301
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I used a chained exception... every time I caught an exception, I chained the old exception along with the new one I was create and along with a nice message for the user... then in the GUI I would use a pop-up to display that message. I didnt do anything with the stack trace except mention that it would be an enhancement to log it for the developer of the system.
 
Paul Sun
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why chained exception should be used? When an error is catched an error flag can be returned
to parent class...to client, and a nice message
will be displayed. Could you tell me the reason?
Thans again.
Paul Sun
SCJP
 
Nate Johnson
Ranch Hand
Posts: 301
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Sun:
Why chained exception should be used? When an error is catched an error flag can be returned
to parent class...to client, and a nice message
will be displayed. Could you tell me the reason?

I am not saying they have to be used, just that I liked the idea of keeping a running stack trace that could help a developer all the way back to the beginning of a problem.
I will stay that your way sound like an old C approach to things... not very object oriented to return error codes. That is just my opinion though.
 
Mark Spritzler
ranger
Sheriff
Posts: 17276
6
IntelliJ IDE Mac Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just keep throwing the exception up until the class that needs to display something does. For instance if the Server error I get happens when a client makes a request, the exception gets passed up to the client GUI, which then displays a pretty JDialog explaining the problem.
If there is a Server error caused when the Server starts up, then the nice pretty message shows up in the Server GUI for the Server Admin to handle. No need for Exception Chaining in this application. Now if you want to wrap the actual Exception into a custom Exception you created and want to see the Stack trace then Exception Chaining is the way to go. But still in this case you still have to pass the Exception up to the method that you want to use to handle the Exception.
Mark
 
Michael Morris
Ranch Hand
Posts: 3451
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did it exactly like Mark. Nothing fancy, just get the message to the right party describing the problem.
Michael Morris
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic