繁体   English   中英

有没有办法在任何未捕获的异常期间执行代码块?

[英]Is there a way to execute a block of code during any uncaught exception?

我意识到这是一个黑暗的镜头,而不是最佳实践或解决方法,但是我想做特定的日志记录信息,因为会抛出异常。 Web表单的状态不要更改,这一点很重要。

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)
try
{
    ExceptionProneCode()
}
catch(Exception ex)
{
    WriteToSomeLogFile(ex.Message);

    //if you want the exception to bubble up from this point, 
    //than you would type "throw;"
}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM