Two Laptop Bag*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes How to deal with exceptions about property file errors? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "How to deal with exceptions about property file errors?" Watch "How to deal with exceptions about property file errors?" New topic
Author

How to deal with exceptions about property file errors?

Zhixiong Pan
Ranch Hand

Joined: Jan 25, 2006
Posts: 239
Hi ranchers,
First I want to show you my strategies solving some cases of property file error.
While starting the server, if property ServerPort is absent or if is not a number, in the RemoteException caught scope, I will pop a configuration dialog to let the user re-configure ServerPort.
While starting the remote client, if property ClientPort is absent or if is not a number or if it can't connect to server, I will pop a configuration dialog to let the user re-configure ClientPort.
But I don't know how to deal with property AloneDBFile's absence while starting alone client, in that case Data's initDB method will throw an IOException which will be caught in Data's constructor and re-throw a RuntimeException. That RuntimeException makes the application terminal. Should I catch that RuntimeException and pop out a configuration dialog to let the user re-configure AloneDBFile?
Thanks.


SCJP 1.4 SCJD
Mark Smyth
Ranch Hand

Joined: Feb 04, 2004
Posts: 288
Why do you need to rethrow the IOException as a RuntimeException in the constructor. In the constructor of my Data class I check if the file exists, if it can be written to and finally that it is a valid data file. If not I throw a checked IOException (or the subclass FileNotFoundException). There are no constraints on the signature of your constructor (as it can't be in the DBMain interface) and you can therefore throw any Excptions you like from here, so there is no need to wrap it in a RuntimeException.

Just catch the IOException and handle it as you normally handle exceptions for other modes, ie exit the app or show the connection dialog again.

Mark.


SCJP<br />SCJD
Rudolph Jen
Ranch Hand

Joined: Nov 17, 2006
Posts: 37
>exit the app

I like this. I have to check, but I can't remember to have any wished behavior in case of an error in may assignment. Therefor I try to keep it as simple as possible. I like ASAP

Best regards,
R


SCJP<br />SCJD (in progress)
Vincent Li
Greenhorn

Joined: Jan 12, 2007
Posts: 22
Originally posted by Zhixiong Pan:

...
But I don't know how to deal with property AloneDBFile's absence while starting alone client, in that case Data's initDB method will throw an IOException which will be caught in Data's constructor and re-throw a RuntimeException. That RuntimeException makes the application terminal. Should I catch that RuntimeException and pop out a configuration dialog to let the user re-configure AloneDBFile?


Hi,

With they way you seem to have designed it, I'd think you can simply check if you have the parameter in the first place before you even attempt the connect. If you don't have it, then ask for configuration. If it fails, just exit.

The way I've went about mine is always popup the config dialog and populate the fields with either hard-coded defaults or values from the properties file. Any time the user changes the property, it's saved back to the properties file. When error encountered with the connection, just pop the config dialog back up to either reconfigure or exit.

Vince
SJCP (1.4), SCWCD (1.4), SCJP (almost there!)
[ January 30, 2007: Message edited by: Vincent Li ]

Vince<br />SCJP(1.4), SCWCD(1.4), SCJD (5.0)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to deal with exceptions about property file errors?
 
Similar Threads
Two questions before submitting.
socket udp programming
Problem in UDP client/server application
Problem in UDP client/server application....
B&S suncertify.properties