Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can I throw RNF exception in constructor of data.java

 
Andy Zhu
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did some initializations in data() including open the db file, which throws IOException and is wrapped into RecordNotFoundException, now my problem is this: can I have the constructor throw rnf exception or I have to handle this within the constructor?

I prefer the second since the gui part will be able to see some message. However, I am not sure what sun wants since my instruction doesn't say anything about this. Alternatively, I can put a public init() which throws this rnf ex, but this function isn't specified in the interface? I don't know how you handle these?

Thanks
 
Itapaj� Takeguma
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Andy Zhu:
I did some initializations in data() including open the db file, which throws IOException and is wrapped into RecordNotFoundException, now my problem is this: can I have the constructor throw rnf exception or I have to handle this within the constructor?

I prefer the second since the gui part will be able to see some message. However, I am not sure what sun wants since my instruction doesn't say anything about this. Alternatively, I can put a public init() which throws this rnf ex, but this function isn't specified in the interface? I don't know how you handle these?

Thanks


Can't you throw a InitializationProblemException? I think RNF should be thrown when the record was not found. I think that if a Data Instance cannot be created, then nothing can be done and, unfortunately, the client won't do nothing.
 
Andy Zhu
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey, Itapaj�:

thanks for your comments. first I need to say a bit of my implementation of the interface. I have an init() which does some initialization of the "server", includes opening the database file. I wrapped io ex into rnf ex (at least this makes sense to me because say, if the file doesn't exist, of cause, it is rnf). The Data() constructor will call init so that all the db initialization will be able to done at the time of data object construction. Now the question is: how do I handle these ex, in my case rnf ex? Sun doesn't say a word of the constructor. In my situation, I try to disallow default constructor and force the use of the constructor with ex throw (this will give a chance to server gui to catch ex). That comes my previous question. I don't know if Sun allows this type of management.
 
Itapaj� Takeguma
Ranch Hand
Posts: 41
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Andy Zhu:
Hey, Itapaj�:

thanks for your comments. first I need to say a bit of my implementation of the interface. I have an init() which does some initialization of the "server", includes opening the database file. I wrapped io ex into rnf ex (at least this makes sense to me because say, if the file doesn't exist, of cause, it is rnf). The Data() constructor will call init so that all the db initialization will be able to done at the time of data object construction. Now the question is: how do I handle these ex, in my case rnf ex? Sun doesn't say a word of the constructor. In my situation, I try to disallow default constructor and force the use of the constructor with ex throw (this will give a chance to server gui to catch ex). That comes my previous question. I don't know if Sun allows this type of management.


the problem when you throw the rnf instead of a IOException is that you loose some meaning. If you want more details, you must do:



I haven't decided about these exceptions. I'll think about an Adapter.
Oh, i think theres no problem to throw whatever exception u want to throw in the constructor.

Itapaj�.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic