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

Trouble with the exception handling in the Database implementation.

 
Elena Taube
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
In my design I have defined the Database class that makes all I/O operations with the database file. This class is a singleton. It has a private constructor where I initialize the database schema.
The problem that I have is the throws-signature in all method of the Database class.

The private constructor and the method, that returns the instance of the Database (getConnection()) throws DataSchemaException.
All other public method in the Database throws IOException, like this:


Could you help me with the correct exception handling.
Is this throwing of the exception correct? Or should I throw something like DatabaseException and throw it in the constructor and all method.

What is the "best practice" and correct design in this situation?

any ideas and recommendations are highly appreciated.
Thanks a lot for your help!
Kind regards,
 
Martin Sturzenhecker
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Elena,

both solutions look good to me, yet you have to decide on one.

I personally like method signatures having very specific throws clauses. This makes it easier to handle them if you need it and API-readers can easily identify the exceptions that may occur.

Throwing an IOException is less meaningful than throwing a FileNotFoundException and/or EOFException and/or RemoteException.

I hope this helps a little.

cheers
martin
[ December 12, 2005: Message edited by: Martin Sturzenhecker ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic