N
n33470
Hi all,
Is there a way to display a modal dialog in the
AppDomain.CurrentDomain.UnhandledException delegate?
I'd like to display a custom dialog, in addition to logging the error,
on any globally unhandled exceptions. I have registered for the
UnhandledException, but while that method runs the modal dialog shows,
but the app keeps shutting down and terminates. Is there a known
limitation that restricts showing forms during the global exception
handler?
Here is a small sample that gives you the basic idea. I put a button
click event on the Login screen that deliberately throws an
ApplicationException. The MessageBox in the delegate shows for a
moment, but then the app terminates. I'm running on the emulator and
this behavior happens both with and without the debugger.
[MTAThread]
static void Main()
{
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(OnUnhandledException);
Application.Run(new Login());
}
public static void OnUnhandledException(Object sender,
UnhandledExceptionEventArgs e)
{
Exception ex = e.ExceptionObject as Exception;
if (ex != null)
{
this.LogError(ex);
MessageBox.Show(ex.Message, "Unhandled Exception");
}
}
Thanks!
--steve
Is there a way to display a modal dialog in the
AppDomain.CurrentDomain.UnhandledException delegate?
I'd like to display a custom dialog, in addition to logging the error,
on any globally unhandled exceptions. I have registered for the
UnhandledException, but while that method runs the modal dialog shows,
but the app keeps shutting down and terminates. Is there a known
limitation that restricts showing forms during the global exception
handler?
Here is a small sample that gives you the basic idea. I put a button
click event on the Login screen that deliberately throws an
ApplicationException. The MessageBox in the delegate shows for a
moment, but then the app terminates. I'm running on the emulator and
this behavior happens both with and without the debugger.
[MTAThread]
static void Main()
{
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(OnUnhandledException);
Application.Run(new Login());
}
public static void OnUnhandledException(Object sender,
UnhandledExceptionEventArgs e)
{
Exception ex = e.ExceptionObject as Exception;
if (ex != null)
{
this.LogError(ex);
MessageBox.Show(ex.Message, "Unhandled Exception");
}
}
Thanks!
--steve