Win a copy of Android Programming: The Big Nerd Ranch Guide this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Exception handling  RSS feed

Luc Feys
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 918
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!