开发者

Handling exceptions but where ? Service Layer or Controller?

I was wondering where exactly do you handling exception ? it is in the service layer or the controller ?

If an error happen in the service layer.. and that this error must somehow be showed to the user.. how do we proceed开发者_如何学编程 ?

EDIT

I will explain, bring in context an account where the user have to specify username and password.. if that go through the AuthentificationService and that the username and password doesnt match i have to tell the user.. how i handle this scenario ? is the service layer will throw an exception ?

Thanks.


It depends on the exception.

For some exceptions you'll simply want to log them and carry on. For others you'll want to inform the user about something.

A specific example I had recently was an in-house app that relies on some web services. When the web services are not responding the app doesn't work.

In this scenario a WebException is thrown and I use that to inform the user that the service will not work at this time.

In this case, I handle the exception in my service layer and I also let it propogate up the chain so I can react to it in the controller.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜