即使發生未處理的異常,也會調用Page_Unload。我需要處理這種情況。如何在Page_Unload中檢測到已發生未處理的異常?
當變量在Page_Unload中處於不正確的狀態時,我有一個變量狀態驗證拋出異常。 Application_Error
在Global.asax
後處理的例外。當另一個異常已經發生時,我需要禁止引發異常。
頁:
public partial class _Default : System.Web.UI.Page
{
private int tst = 0;
protected void Page_Load(object sender, EventArgs e)
{
tst = tst/tst; //causes "Attempted to divide by zero."
tst = 1;
}
protected void Page_Unload(object sender, EventArgs e)
{
if (tst == 0) throw new Exception("Exception on unload");
}
}
的Global.asax:
void Application_Error(object sender, EventArgs e)
{
// Get the error details
Exception lastErrorWrapper = Server.GetLastError();
System.Diagnostics.Debug.Print(lastErrorWrapper.Message);
}
我需要得到「試圖除以零。」在Global.asax
但我正在逐漸「上卸載例外」
給出大幅度簡化的例子。真實情況包括用戶控制和條件編譯。
我不能解決Page_Load
的情況(例如通過捕捉異常)。
我編輯了你的標題。請參閱:「[應該在其標題中包含」標籤「](http://meta.stackexchange.com/questions/19190/)」,其中的共識是「不,他們不應該」。 – 2013-05-07 10:41:25