Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to deal with exceptions about property file errors?

 
Zhixiong Pan
Ranch Hand
Posts: 239
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Mark Smyth
Ranch Hand
Posts: 288
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Rudolph Jen
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
>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
 
Vincent Li
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic