private void ShowThreadExceptionDialog(object ex) { var newLine = Environment.NewLine; var errorMessage = String.Empty; if (ex.GetType().IsAssignableFrom(typeof(System.Exception))) { var systemException = (Exception)ex; errorMessage = "Unhandled Exception: " + systemException.Message + newLine + "Exception Type: " + systemException.GetType() + newLine + "Stack Trace:" + newLine + systemException.StackTrace; } else { errorMessage = ex.ToString(); } var exceptionForm = new ThreadExceptionHandlerForm(errorMessage); if (exceptionForm.ShowDialog() == DialogResult.Abort) { Application.Exit(); } }