• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

throwing an exception on a property set

 
Kevin Broderick
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • 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
 
Roel De Nijs
Sheriff
Posts: 10666
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • 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
  • 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: 10666
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I did!

 
Kevin Broderick
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers Roel
 
Kevin Broderick
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • 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: 10666
144
AngularJS Chrome Eclipse IDE Hibernate Java jQuery MySQL Database Spring Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you check the javadoc of JOptionPane? That will certainly answer your question.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic