【问题标题】:avoiding try catch code on the dao layer and catching it on the service layer避免在dao层尝试捕获代码并在服务层捕获它
【发布时间】:2013-01-16 19:08:57
【问题描述】:

我有一个引用 dao 层的服务层。我使用ninject的反转控制来绑定实现。

public class DaoA : IDaoA
{   
    private DaoA _dao;
    public void daoMethod() {
       //throw DBUpdate exception   
    }    
}


public class ServiceA : BaseService 
{   
    private DaoA _dao;
    public result methodA() {
       _dao.daoMethod();    
    }
}

现在我想避免daoMethod 中的try catch 块。有没有办法可以在某些BaseService 捕获这个异常 就像我们在 .NET 的 Attribute 类中捕获 OnException 方法一样?

【问题讨论】:

标签: asp.net .net asp.net-mvc-3 ninject


【解决方案1】:

是的,如果你没有在 DAO 层捕获异常,你可以在服务层捕获它。

【讨论】:

  • 是否可以在单独的类中捕获它,从而避免每个服务方法中的 try catch 块的样板代码?这是一个好习惯吗?
猜你喜欢
  • 2021-08-20
  • 1970-01-01
  • 1970-01-01
  • 2015-02-11
  • 1970-01-01
  • 2011-02-26
  • 2016-03-27
  • 2012-01-28
  • 1970-01-01
相关资源
最近更新 更多