0

我意识到这是在黑暗中拍摄,而不是最佳实践或解决方法,但我想在抛出异常时做特定的日志记录信息。重要的是 Web 表单的状态不会改变。

4

3 回答 3

2
You can use 

    try
    {

    }
    catch(Exception ex)
    {
      //your treatment does not contain throw ex.
      //mute exception in order to not change state
    }

You can use this in your webform or in your gloabl.asax in Application_Error (in order to centralize exception treatment)
于 2012-07-24T19:09:13.673 回答
1
try
{
    ExceptionProneCode()
}
catch(Exception ex)
{
    WriteToSomeLogFile(ex.Message);

    //if you want the exception to bubble up from this point, 
    //than you would type "throw;"
}
于 2012-07-24T19:09:52.700 回答
0

如果我们在 ASP.NET 的上下文中讨论,Application_Error事件将是放置全局异常日志记录块的好地方。

于 2012-07-24T19:10:51.020 回答