【发布时间】:2014-02-26 11:33:29
【问题描述】:
我有一个带有 DAL 和服务层(WCF Rest)的应用程序。使用IErrorHandler 在服务层中出现错误。
在 DAL 层中,我在所有方法中使用 try catch,并将错误记录到 catch 中的文本文件中。之后我使用 throw 抛出错误。
我的 DAL 层方法如下
public DataTable Method1()
{
DataSet dsData = null;
try
{
//code to get the data
}
catch (Exception ex)
{
dbManager.WriteErrorLog(module, MethodBase.GetCurrentMethod().Name, ex.Message);
throw;
}
return dsData.Tables[0];
}
在 catch 中,我使用了一个名为 WriteErrorLog 的通用方法将异常写入文本文件。
我的困惑是我们已经在服务层处理了错误。所以我可以避免在我的 DAL 中使用 try .. catch 吗?还是现有的 DAL 是好的做法?
【问题讨论】:
标签: c# wcf exception-handling layer