• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Adapter pattern and general exception.

 
Ranch Hand
Posts: 58
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 197
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic