Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Adapter pattern and general exception.

 
Omar Kalaldeh
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

At database design I used Adapter pattern and came out with the following issue.

Should adapter class throw a general exception such as DatabaseException, or should it specify thrown exceptions ( ex: SecurityException, recordNotFoundException,..).

The problem with specified exception, it is hard to define all exceptions should be thrown by a method, and even if I could, it will be a long list.

Ex: Update method
With assignment database class, this method will throw RecordNotfoundException and SecurityException. On another database implementation it could throw new exceptions such as InvaildDataType, ColumnNotFoud, TableNotFound�..

So should the Adapter class throws a general exception, or throw every expected exception.

I am some how with throwing a general exception, what comfort me more about this choice is how JDBC API works, where it throws a general SQL Exceptions.
I know we are talking about totally deferent approach with JDBC since the main idea in JDBC is to execute SQL statements, and not calling database methods, but at the end the results are the same.

Any comment is appreciated.

Best regards.
 
mike acre
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, throw a general exception and chain the specific exception within it.
You can do the same with RemoteExceptions by wrapping the Remote object in an adapter client side and extracting the RemoteException and rethrowing a general 'transport' exception.
 
Omar Kalaldeh
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi mike,

thank you for your reply,

It is always good to have a second opinion,

As for RemoteException I am using sockets not RMI.

Thank you again.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic