Another approach is to wrap the main code in a try catch. Not sure why there is a difference between debug and release.
{
try
{
AppDomain.CurrentDomain.UnhandledException +=
new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Updater());
}
catch (Exception ex)
{
CaughtException(ex);
}
}
public static void CaughtException(Exception ex)
{
try
{
StreamWriter streamUnhadeled = new StreamWriter("erreurs non gérées.txt", true);
streamUnhadeled.WriteLine("-----------------------------------"+ DateTime.Now.ToString() +"-----------------------------------------");
streamUnhadeled.WriteLine(ex.Message);
streamUnhadeled.WriteLine(ex.StackTrace);
streamUnhadeled.WriteLine(ex.InnerException);
streamUnhadeled.WriteLine(ex.TargetSite);
streamUnhadeled.WriteLine(ex.Source);
streamUnhadeled.Flush();
streamUnhadeled.Close();
streamUnhadeled.Dispose();
MessageBox.Show("Oops ! Contactez nous "
+ "avec les informations suivantes :\n\n" + ex.Message + ex.StackTrace,
"Erreur fatale", MessageBoxButtons.OK, MessageBoxIcon.Stop);
}
finally
{
Application.Exit();
}
}