簡體   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