2012-10-16 101 views
0

我正在使用下面的代碼來處理未處理的異常。未處理的異常代碼不起作用

private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) 
    { 
     if (System.Diagnostics.Debugger.IsAttached) 
     { 
      // An unhandled exception has occurred; break into the debugger 
      System.Diagnostics.Debugger.Break(); 
     } 


     e.Handled = true; 
     Error.Exp = e.ExceptionObject; 
     (RootVisual as Microsoft.Phone.Controls.PhoneApplicationFrame).Source = new Uri("/Error.xaml", UriKind.Relative); 
    } 

此代碼應直接控制Error.xaml頁,但它(甚至註釋掉if塊之後)去與異常的錯誤信息的Visual Studio。這裏有什麼問題?

錯誤的來源是

GeneralTransform generalTransform1 = canvas1.TransformToVisual(start_rec); 

錯誤消息是 「參數異常是未處理的,該參數是不正確」。

+0

在未發生異常的情況下,您想要執行的操作有一些問題。看看這裏:http://stackoverflow.com/questions/7926155/displaying-error-page-in-wp7-app –

回答

0
 try 
     { 
        // do something with your crash , report it or write log 
     } 
     catch 
     { 
     } 
     if (System.Diagnostics.Debugger.IsAttached) 
     { 
      // An unhandled exception has occurred; break into the debugger 
      System.Diagnostics.Debugger.Break(); 
     } 

調試到異常拋出。

+0

我不想去調試。我想要顯示'error.xaml'。 –