• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

loading from properties file

 
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bartender
Posts: 1872
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 264
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Andrew and Phil...
I was tied with some other work for a few days. Back on this again now....
Dushy
 
Tongue wrestling. It's not what you think. And here, take this tiny ad. You'll need it.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic