Link to home
Start Free TrialLog in
Avatar of anonymous
anonymous

asked on

Java Message handling in Service Layer

I´m designing a service layer in a multilayerd architecture (Service, Business, Dao). Suposse I need a method like getUserAccounts

This method just return a list of Accounts, but what if my dao layer can´t connect to database, or if I have some error when reading the recorset, a parse problem for example. Or maybe another error in the business layer.

Do I have to catch the exception in the service layer, and map to a error code?
Do I have to catch the exception in the business layer, and the buisness layer return a bean with the error code? Avoiding to have any kind of logic in the service layer, more than exposing the Rest API
ASKER CERTIFIED SOLUTION
Avatar of gurpsbassi
gurpsbassi
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of anonymous
anonymous

ASKER

Great! If the exception is in the DAO Layer should I catch it in the Business layer also? or only in the service layer?
Avatar of dpearson
You should always catch Exceptions at the level of the system that knows how to correctly handle that exception.

In other words, "it depends".  If you know what to do at the business layer to handle the exception (e.g. database offline, let's check the cache) then handle it there.

But if you need to return to the user "it didn't work" you should let it bubble up to the service layer and send the error out to the user.

Doug