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

bit*_*key 4 c# asp.net-mvc elmah

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

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

Xha*_*rze 10

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

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

try {
  ...
}
catch (Exception e) {
  Elmah.ErrorSignal.FromCurrentContext().Raise(e)
}
Run Code Online (Sandbox Code Playgroud)