Handling Dao exceptions in service layer

后端 未结 4 1491
温柔的废话
温柔的废话 2020-12-13 04:47

If my Dao layer throws Dao specific exceptions, then does handling them in my service layer consitute a leakage of concerns? If yes, then should I make the exceptions generi

4条回答
  •  青春惊慌失措
    2020-12-13 05:21

    Good question..!! Handling exceptions at the UI layer (for example, actions layer if you are using struts) is the good approach.Making exceptions generic is not a good way to deal with this issue. Every layer should have however their specific exceptions as generic. for example, DAO layer may have custom exception handlers like DavaSavingException, IOException etc..

    So the approach is throw exception from DAO to service layer and again throw it to UI layer and catch in UI specific classes.

    However things are too diplomatic depending upon your applications/needs.

提交回复
热议问题