This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Adapter pattern and general exception. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Adapter pattern and general exception." Watch "Adapter pattern and general exception." New topic
Author

Adapter pattern and general exception.

Omar Kalaldeh
Ranch Hand

Joined: Jun 08, 2004
Posts: 58
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.


Best Regards <br /> <br />Omar F. Kalaldah<br />---------------------<br />SCJP, SCJD, SCBCD
mike acre
Ranch Hand

Joined: Sep 23, 2003
Posts: 197
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.


SCJP 1.4, SCJD
Omar Kalaldeh
Ranch Hand

Joined: Jun 08, 2004
Posts: 58
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.
 
 
subject: Adapter pattern and general exception.
 
Similar Threads
NX:exception handling in Data class
Exception handling again
operating mode--share code
B&S Data exceptions
RuntimeException or Exception