
Untitled
By: a guest on
Sep 30th, 2013 | syntax:
None | size: 1.43 KB | hits: 26 | expires: Never
static void Main(string[] arg)
{
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.ThreadException += new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run( ... );
}
static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs e)
{
MessageBox.Show(e.Exception.ToString());
}
static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
MessageBox.Show((e.ExceptionObject as Exception).ToString());
}
Private Sub Application_DispatcherUnhandledException(ByVal sender As Object, ByVal e As System.Windows.Threading.DispatcherUnhandledExceptionEventArgs) Handles Me.DispatcherUnhandledException
'TODO: Log error'
Dim sb As New System.Text.StringBuilder(e.Exception.Message & vbCrLf)
Dim ex = e.Exception.InnerException
While ex IsNot Nothing
sb.AppendLine("______________ inner exception: ______________")
sb.AppendLine(ex.Message)
sb.AppendLine(vbCrLf)
ex = ex.InnerException
End While
If MessageBox.Show(sb.ToString, "Exception caught", MessageBoxButton.OKCancel) = MessageBoxResult.Cancel Then Stop
e.Handled = True
End Sub