A few days ago I stumbled over the problem that while developing using the Visual Studio NET IDE the MM error handling worked fine, but the release version of my program did not log exceptions, instead I got an "unhandled error" message.
After investigating the problem I found a similar message at dotnet247:
http://dotnet247.com/247reference/msgs/6/34274.aspxSo instead of using the standard setup:
class AppMainEntry : mmMainEntry
{
///
/// Static field that contains a reference to the application object
/// public static AppDesktop App;
///
/// Main application entry point
/// [STAThread]
public static void Main()
{
try
{
// Instantiate the Application Object
App = new AppDesktop();
// more code here [...]
// Instantiate the main application form
if (result == DialogResult.OK)
{
Application.Run(new MainForm());
}
}
catch (Exception e)
{
mmAppBase.Log.WriteException(e);
// Display the Exception form
mmExceptionForm ExceptForm = new mmExceptionForm(e.Message, e.StackTrace);
ExceptForm.ShowDialog();
}
finally
{
MessageBox.Show("finally");
}
}
}
I now use:
class AppMainEntry : mmMainEntry
{
///
/// Static field that contains a reference to the application object
/// public static AppDesktop App;
///
/// Main application entry point
/// [STAThread]
public static void Main()
{
Application.ThreadException +=new System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
// Instantiate the Application Object
App = new AppDesktop();
// more code here [...]
// Instantiate the main application form
if (result == DialogResult.OK)
{
Application.Run(new MainForm());
}
}
private static void Application_ThreadException(object sender, System.Threading.ThreadExceptionEventArgs et)
{
Exception e = et.Exception;
mmAppBase.Log.WriteException(e);
// Display the Exception form
mmExceptionForm ExceptForm = new mmExceptionForm(e.Message, e.StackTrace);
ExceptForm.ShowDialog();
Application.Exit();
}
}
Maybe this is of help to others.
Greetings from Hamburg!
Soenke