In our app, these are the layers used:
Rest Service Endpoint Layer --> Business Layer --> DAO --> ORM
Now, each layer translates its exceptions appropriately and sends them to the next layer. For example, DAO Layer
creates a DaoException
and throws to Business Layer
, Bussiness Layer
translates this to BusinessException
which throws it to RestService Layer
where it is handled by a cxf mapper (okay, not really in RestServiceLayer).
We have put @Transactional
on the methods of Business Layer
. So, if an exception happens at commit, the exception
will be fist seen only in the Rest Service Endpoint Layer
. Now, I will have to check for transaction commit related exceptions(eg. RollBackException etc.
) in the topmost layer (Rest Service Endpoint Layer
), which would kind of defeat the purpose of each layer translating the exceptions for the next layer.
What would be a good way of dealing with this situation? Should I not translate exceptions at all and handle all of them only on the topmost layer?