0
我想捕獲和記錄在我的Silverlight 5應用程序中發生的未處理的異常。我已經連接了Application.UnhandledException委託。問題是,在拋出異常之後,我能做什麼和不能做什麼?這個Silverlight應用程序運行在託管WebControl(IE引擎)的C++應用程序中,並且該主機正在實現外部功能。因此,這是Application.UnhandledException的功能是什麼樣子:如何在Silverlight 5中記錄未處理的異常
private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{
var ex = e.ExceptionObject;
// This is a reference to the
var external = External.Instance;
// loop through all the exceptions and call the hosts 'external' method so the
// host is able to write out the error to a local log file
while (external != null && ex != null)
{
external.LogException(ex.Message, ex.StackTrace);
ex = ex.InnerException;
}
// If the app is running outside of the debugger then report the exception using
// a ChildWindow control.
if (!System.Diagnostics.Debugger.IsAttached)
{
// NOTE: This will allow the application to continue running after an exception has been thrown
// but not handled.
// For production applications this error handling should be replaced with something that will
// report the error to the website and stop the application.
e.Handled = true;
ChildWindow errorWin = new ErrorWindow(e.ExceptionObject);
errorWin.Show();
}
}
的目標是記錄錯誤並保持應用程序的運行。
看看這裏:http://stackoverflow.com/questions/228723/silverlight-logging-framework-and-or-best-practices –
你試過了嗎?完整的源代碼樣本與最終解決方案? – Kiquenet