File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Exception handling Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Exception handling" Watch "Exception handling" New topic

Exception handling

Luc Feys

Joined: Nov 21, 2005
Posts: 20

I have a few questions regarding the handling of exceptions in my project. I have created a three tier application:
*) database layer
*) application layer
*) gui

Now I would like to wrap/translate the database layer exceptions in specific application layer exceptions, so the gui is never exposed to database layer exceptions (which should for example make migration to a SQL database easier).

But this brings up a few questions:
*) Could I create a global Exception handler class that translates all database layer exceptions into app layer exceptions, or would this be a bad programming practice? This would make it easy to wrap all database
exceptions in the application layer the same way, without duplicating code.

*) Most of my database layer exceptions are pretty low level and not very interesting for my GUI. Except for 'RecordNotFoundException'. Now I have one general 'DataAccessException', but I feel a distinction might be interessing. Would it be bad practice to wrap the 'suncertify.db.RecordNotFoundException' in a '', so I can give the GUI user the same Exception information without actually exposing any database layer exceptions?

Any thoughts on this are welcome.

Thanks a lot.

Mihai Radulescu
Ranch Hand

Joined: Sep 18, 2003
Posts: 918

Hi Loc

I have the same problem but I prefer to chain the exeptions using the initCause(Throwable cause) from the Throwable. This feature provides enought information about the exception and its causes.
If you use a global Exception handler you must be shore that it provides enought information about the exception(and its possible cause).
An other point is the logging - if you use it. I use the throwing everytime when a method is terminating by throwing an exception.


I agree. Here's the link:
subject: Exception handling
It's not a secret anymore!