Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
    Bookmark Topic Watch Topic
  • New Topic

URLyBird1.3.2 A question about Exception handling of some "fatal" errors.

 
Joe J. Wang
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi dear all,
I have a question about exception handling. Since my assignment requires that all the configuration need to be done by GUI and saved in suncertify.properties file, I am wondering if I should do a complex exception handling or a simple one.
For example, after the user starts the client gui in the first time, he should specify the remote server's ip and port#. After that, he may meet a problem that can't connect to the server. The reason can be a wrong IP or a wrong port, or the server has not been started yet.
1. Complex one will try to specify every exception's source and give out kind of specific explanation for the exception/error. In case of above, the program will tell what is wrong, if the ip is not correct, then it will pop up a dialog to let the user re-input the ip and port#.
2. The simple one will just give out a simple error message, something like "can't connect to the server, please try again". Then clear the properties file and exit the program.
I prefer any simple way to do the assignment. I think the a more complex program will bring me more potential problems/risks. But I am not sure if the simple one is really a good way to pass the exam.
Any input is appreciated!
Joe
 
Dushy Inguva
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Joe,
A general advice going around the forum is to keep things simple unless you are trying to try out ultra-cool stuff.
Any configuration error could be reported by a simple message. So i would stick to a simple error handling strategy.
Dushy
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Report post to moderator
Since, in remote mode the server is started elsewhere, then you know that if they type in the wrong IP address, the server will still be up and running.
So you option of clearing out the GUI and letting them reenter is the best GUI choice.
Now Exception handling in the application as a whole should be kept simple. Meaning you don't have to catch every minute Exception that could happen, but catch the more important ones, especially the ones that the methods are throwing. and at the bottom of the list catch the more general Exception.
Mark
 
Joe J. Wang
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Dushyanth&Mark,
Thanks for the replies!
Mark, I see your point. Keep as simple as possible while trying to solve some problems reasonable. But for that case, how about a user just start the client gui while the remote server is not started yet? Maybe no one will do that except me.
So I still prefer to shut down the system when some "fatal" errors happen and let the user try again from the very beginning. For some other exceptions, just generate a dialog to give some reasons. Do you guys think that is possible to pass the assignment?
Thanks!
Joe
 
Joe J. Wang
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi,
I met a problem on handling the suncertify.properties file on different platforms when I did the testing on different platforms. (I did the assignment on linux--RH9)
As I said in previous posts, I will clear the suncertify.properties file and quit the program when some fatal error occured. Here is the codes.

The code works fine on linux, but doesn't work on the windows(2000/xp). On windows, the f.delete() will always return false. I don't know why the file can't be deleted. Does anybody can give me a ring? Thanks in advance!
Best,
Joe
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Report post to moderator
First, try printing
System.out.println("File: " + f);
System.out.println("exists: " + f.exists());
to see what you're currently dealing with. Then try
File f = new File("suncertify.properties");
or
File f = new File(System.getProperty("user.dir"), "suncertify.properties");
as a more platform-neutral way to find a particular file.
 
Joe J. Wang
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Jim,
Thanks for the reply!
I tried that. All the information is correct. The file is the suncertify.properties and the path are correct. And file.exits() returns true. But the file just can't be deleted. Don't know why...
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Report post to moderator
Well, have you opened any FileInputStreams or other classes which access this file? Are you sure that you closed such objects before attempting to delete the file?
I find the delete() method rather annoying because it provides so little feedback on why it fails. But in my experience, the most common problems are (a) the file isn't really where you think it is, or (b) somethign else in the program is holding the file open. Good luck...
 
Joe J. Wang
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Report post to moderator
Hi Jim,
Yeah, there is a FileInputStream and a FileOutputStream that access this file. But I close them and assign null to them before I try to delete the file. Is that enough? And the interesting part is the code works on linux. Not sure what is the problem.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Report post to moderator
Followups go here. now please. Moving the question to another forum is OK considering this specific question isn't really an SCJD question anymore - but we don't want people here just repeating answers given elsewhere, so I'm closing this thread.
 
    Bookmark Topic Watch Topic
  • New Topic