• 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

throwing an exception on a property set

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Ranchers,

I have a simple question. Is it an impropper coding standard to throw exceptions on a classes property set? for instance, I have a class ConfigurationFile that takes setting database location, port number, and IP address from the configuration screen through a property setProperties which in turn calls a private member save that creates the system.properties file if necessary and writes to it. In doing so, the operation must be encapulated in try catch blocks, so save throws a windowException and in turn so does setProperties. If there is a problem on saving the settings, the config screen catches the exception on calling the configurations setProperties and displays the exception to the user via JOptionPane.

Now this all works fine in Java I know but is right to have a set property throwing an exception. Please understand if this question is somewhat dim , but I am almost a begginer at Java development.

many thanks
 
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Kevin,

I have a method to set/change the value of 1 property. This method calls a (private) method to save the configuration file. If some IOException occurs while saving the configuration file, I catch this exception and just show an error message (using JOptionPane).

Kind regards,
Roel
 
Kevin Broderick
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Roel,

I just want to make sure by you, if an IOException occurs, do you show the error message inside the private save. If so then this would be perfect

thank you Roel
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, I did!

 
Kevin Broderick
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Cheers Roel
 
Kevin Broderick
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've another question that follows up on this question.

On catching the errors in JOptionPane, is it ok to pass a null as the parent frame?

Thanks
 
Roel De Nijs
Sheriff
Posts: 11604
178
Hibernate jQuery Eclipse IDE Spring MySQL Database AngularJS Tomcat Server Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Did you check the javadoc of JOptionPane? That will certainly answer your question.
 
A feeble attempt to tell you about our stuff that makes us money
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic