![](/img/trans.png)
[英]Is it possible to execute the code in the try block again after an exception in caught in catch block?
[英]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.