wood burning stoves 2.0*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes loading from properties file 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 "loading from properties file" Watch "loading from properties file" New topic
Author

loading from properties file

Dushy Inguva
Ranch Hand

Joined: Jun 24, 2003
Posts: 264
Hi all,
Im having a wrapper around the properties file (No Phil.. this onez tooo simple) Im having methods like

(Hope the above code formats properly !!!)
But, i do not like the idea of cathing a NumberFormatException to throw another exception. It would be ideal if Integer class had a validating method like

What do you guys say?
Dushy
[Andrew: Wrapped code so that post could appear on non scrolling page]
[ October 31, 2003: Message edited by: Andrew Monkhouse ]

SJCP, SCBCD, SJCD, SCDJWS, SCEA (Part I)
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11509
    
  95

Hi Dushy,
But, i do not like the idea of cathing a NumberFormatException to throw another exception.

Why not?
I think this is perfectly valid. You have made a decision to throw an exception if the provided value is invalid. As long as you are willing to justify that original decision, the decision to wrap the NumberFormatException in an IllegalConfigurationException (or a subclass of it) is perfectly reasonable to me. It will make future additional data validation easier - your clients are already catching the nice generic exception, rather than trying to catch the multitude of different exceptions that you might later want.
It would be ideal if Integer class had a validating method

Not really - it tends to create cluttered code, and it tends to make your normal processing and your error handling all intertwine:

Compared to:

I prefer the second option (although I will entertain arguments against the trinomial expression )
Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Philippe Maquet
Bartender

Joined: Jun 02, 2003
Posts: 1872
Hi Dushy,
Im having a wrapper around the properties file (No Phil.. this onez tooo simple)

I have still such a one, a sort of fa´┐Żade which combines Properties and access to a file. Your solution is 100% OK IMO (and what I called "settings" is a different story).
I agree with Andrew about catching NumberFormatException the way you do. But I hesitate about what to do inside the catch.
As me, in case the file doesn't exist (or the key was manually deleted from the file), you return the default value.
In case the key exists but cannot be converted, you throw your IllegalConfigurationException. In comparison, I simply log the conversion issue at the WARNING level, and return the default value as if it was not found.
I suppose that both options are defendable.
Best,
Phil.
Dushy Inguva
Ranch Hand

Joined: Jun 24, 2003
Posts: 264
Thanks Andrew and Phil...
I was tied with some other work for a few days. Back on this again now....
Dushy
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: loading from properties file