我意识到这是一个黑暗的镜头,而不是最好的做法或方法,但我想做特定的日志信息,因为抛出异常。重要的是Web表单的状态不会改变。
答案 0 :(得分: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)
答案 1 :(得分: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;"
}
答案 2 :(得分:0)
如果我们在ASP.NET的上下文中讨论,那么Application_Error事件将是放置全局异常日志记录块的好地方。