• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Invalid Cookie

 
Chris Harris
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
If I detect an invalid cookie at start of database should I:
a) do System.exit(-1)
OR
b) throw a subclass of RuntimeException
Thanks
Chris
 
Dushy Inguva
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Chris,
Its better not to have System.exit method sprayed in the code.
You could have an initialize method which intializes the database. This method could throw a Checked Exception. The database file being wrong should be considered as a checked exception. (Compare this with that java.sql.DriverManager does when it can't connect to a db for whatever reason)
If the initialization fails, you could catch the exception, and exit from a central place.
Dushy
 
Chris Harris
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Dushy,
Interesting idea. Are you suggesting that I develop a class that is equivalent the DriverManager? As I can not add a getConnection method to the DB interface.
I was planning to use the constructor of the Data class to intializes the database. How about the constructor throwing a DatabaseException if the database can not be initialised.
Chris
 
Dushy Inguva
Ranch Hand
Posts: 264
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Chris,
I guess you are on the right path. It is right if the constructor throws an exception thereby preventing the creation of an object with an invalid state.
About the DriverManager, i am using something like that at the client side to hide the Connection lookup code (local or remote db). At the server side, you could create an instance of the Data class, and store it to be used by all threads (or if you have one instance of Data class per client, not share it)
Dushy
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic