私はアプリケーションでこの例外処理の方法に従ってきました。しかし、私のリードは、私が間違っていると言った。私は単純に同じ例外をラップして再実行しているため、パフォーマンスに影響します。例外のラッピングと再スロー処理はパフォーマンスに影響しますか?
私のアプローチに間違いがありますか?誰も私がここで例外を記録して処理する方法について提案はありますか?
public class BusinessRepository : IBusinessRepo
{
public List<Employee> GetEmployees()
{
try
{
//do some DB operations
}
catch (SQLException sqlex)
{
Logger.Log("Exception detail with full stack trace");
throw new DALException(sqlex, "Error in data access layer");
}
}
}
public class BusinessLayerClass : IBusinessLayer
{
private readonly IBusinessRepo Repo;
public BusinessLayerClass(IBusinessRepo rep)
{
Repo = rep;
}
public List<Employee> GetEmployees()
{
try
{
List<Employee> emps= return Repo.GetEmployees();
}
catch (DALException dex)
{
//do nothin as it got already logged
throw;
}
catch (Exception ex)
{
Logger.Log(ex, "Business layer ex");
throw new BusinessLayerEx(ex);
}
}
}
public class HomeController : Controller
{
public ActionResult Index()
{
try
{
List <Employee>= BusinessLayerClass.GetEmployees();
}
catch (DALException)
{
//show error msg to user
}
catch (BusinessLayerEx)
{
//show error msg to user
}
catch (Exception ex)
{
Logger.Log();
//show error msg to user
}
return View(emps);
}
}
私は、上記の泡立ちとハンドリングやロギングの正しい道をたどるのですか?私がいる限り2つの条件が満たされているとして、これを行うためのあなたの方法に同意に傾いている
johnのスケルトンによると、パフォーマンスは例外のスローによってほとんど影響を受けません。参照してください:http://www.developerfusion.com/article/5250/exceptions-and-performance-in-net/ – albertjan
例外は例外的なものでなければならないので、大したことですか? – emartel
@albertjan私はJon Skeetに同意します。しかし、私のアプローチは正しい方法で対処し、ログに記録していますか? – Billa