可以使用Elmah而不是try / catch吗?

问题描述 投票:4回答:1

我一直在使用Elmah作为MVC应用程序,我的问题是

使用Elmah时不写try catch语句是不好的做法?

c# asp.net-mvc elmah
1个回答
10
投票

ELMAH用于记录未处理的异常。如果你可以处理异常,我强烈建议你这样做。

如果您仍想将例外记录到ELMAH,您可以这样做:

try {
  ...
}
catch (Exception e) {
  Elmah.ErrorSignal.FromCurrentContext().Raise(e)
}
© www.soinside.com 2019 - 2024. All rights reserved.