GeeCON Prague 2014*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes About Exception. 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 "About Exception." Watch "About Exception." New topic
Author

About Exception.

Paul Sun
Greenhorn

Joined: Aug 26, 2002
Posts: 19
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

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


scwcd, scjd, scjp<br /><a href="http://natejohnson.us" target="_blank" rel="nofollow">http://natejohnson.us</a><br /><a href="http://rice.kuali.org" target="_blank" rel="nofollow">http://rice.kuali.org</a>
Paul Sun
Greenhorn

Joined: Aug 26, 2002
Posts: 19
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

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

Joined: Feb 05, 2001
Posts: 17250
    
    6

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


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
I did it exactly like Mark. Nothing fancy, just get the message to the right party describing the problem.
Michael Morris


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
 
GeeCON Prague 2014
 
subject: About Exception.