Pastebin launched a little side project called HostCabi.net, check it out ;-)Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Sep 30th, 2013  |  syntax: None  |  size: 1.43 KB  |  hits: 26  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. static void Main(string[] arg)
  2.     {
  3.         AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
  4.         Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
  5.         Application.EnableVisualStyles();
  6.         Application.SetCompatibleTextRenderingDefault(false);
  7.         Application.Run( ... );
  8.     }
  9.  
  10.     static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
  11.     {
  12.         MessageBox.Show(e.Exception.ToString());
  13.     }
  14.  
  15.     static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
  16.     {
  17.         MessageBox.Show((e.ExceptionObject as Exception).ToString());
  18.     }
  19.        
  20. Private Sub Application_DispatcherUnhandledException(ByVal sender As Object, ByVal e As System.Windows.Threading.DispatcherUnhandledExceptionEventArgs) Handles Me.DispatcherUnhandledException
  21.     'TODO: Log error'
  22.  
  23.     Dim sb As New System.Text.StringBuilder(e.Exception.Message & vbCrLf)
  24.  
  25.     Dim ex = e.Exception.InnerException
  26.     While ex IsNot Nothing
  27.         sb.AppendLine("______________ inner exception: ______________")
  28.         sb.AppendLine(ex.Message)
  29.         sb.AppendLine(vbCrLf)
  30.         ex = ex.InnerException
  31.     End While
  32.  
  33.     If MessageBox.Show(sb.ToString, "Exception caught", MessageBoxButton.OKCancel) = MessageBoxResult.Cancel Then Stop
  34.     e.Handled = True
  35. End Sub