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.
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.
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
Joined: May 13, 2002
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.
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