即使异常没有冒泡到应用程序,ELMAH是否也会记录异常?我想在发生异常时弹出一条消息并仍然记录异常。目前我一直在尝试捕获块并吐出消息,但这变得乏味。
问问题
14952 次
2 回答
129
ELMAH has been updated to support a new feature called Signaling.
This allows you to handle exceptions how you want, while still logging them to ELMAH.
try
{
int i = 5;
int j = 0;
i = i / j; //Throws exception
}
catch (Exception ex)
{
MyPersonalHandlingCode(ex);
ErrorSignal.FromCurrentContext().Raise(ex); //ELMAH Signaling
}
Re-throwing exceptions can be a bad practice as it makes it difficult to trace the flow of an application. Using Signaling is a much better approach if you intended to handle the error in some fashion and simply want to document it.
Please check out this excellent guide by DotNetSlackers on ELMAH
于 2009-05-08T19:33:36.887 回答
6
过滤器是处理这个问题的最干净的方法。在此处检查此解决方案https://stackoverflow.com/a/5936867/965935
于 2012-12-13T00:23:09.420 回答