T
TS
The method that is envoked using an asynCallback to asynchronously call a
web method. I read the following article and implemented what it said:
http://msdn.microsoft.com/msdnmag/issues/04/06/NET/. It says that the
Application.ThreadException won't catch exceptions of other threads, so this
asyncCallback's exception would not be caught in this situation. It says
that i also have to catch the CLR's
AppDomain.CurrentDomain.UnhandledException. I implemented it, but the
exception is still not being caught. Can anyone tell my what i am doing
wrong?
The Loader class is the starting object that sets up all the event handling.
If you need the code for the asyncCallback method, let me know.
public class Loader
{
[STAThread]
public static void Main()
{
try
{
SubMain();
}
catch (Exception e)
{
HandleUnhandledException(e);
}
}
public static void SubMain()
{
// add the hook to catch all CLR unhandled exceptions (asyncronous method
calls, etc.)
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(OnUnhandledException);
// add the hook to catch all windows forms' unhandled exceptions
Application.ThreadException+=new
System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
Application.Run(new UIPStarter());
}
// CLR unhandled exception
private static void OnUnhandledException(Object sender,
UnhandledExceptionEventArgs e)
{
HandleUnhandledException(e);
}
// Windows Forms unhandled exception
private static void Application_ThreadException(object sender,
System.Threading.ThreadExceptionEventArgs e)
{
HandleUnhandledException(e);
}
static void HandleUnhandledException(Object o)
{
Exception e = o as Exception;
BaseForm.ReportException(e);
MessageBox.Show("An unhandled exception occurred and the application is
shutting down.");
Application.Exit();
}
}
}
web method. I read the following article and implemented what it said:
http://msdn.microsoft.com/msdnmag/issues/04/06/NET/. It says that the
Application.ThreadException won't catch exceptions of other threads, so this
asyncCallback's exception would not be caught in this situation. It says
that i also have to catch the CLR's
AppDomain.CurrentDomain.UnhandledException. I implemented it, but the
exception is still not being caught. Can anyone tell my what i am doing
wrong?
The Loader class is the starting object that sets up all the event handling.
If you need the code for the asyncCallback method, let me know.
public class Loader
{
[STAThread]
public static void Main()
{
try
{
SubMain();
}
catch (Exception e)
{
HandleUnhandledException(e);
}
}
public static void SubMain()
{
// add the hook to catch all CLR unhandled exceptions (asyncronous method
calls, etc.)
AppDomain.CurrentDomain.UnhandledException += new
UnhandledExceptionEventHandler(OnUnhandledException);
// add the hook to catch all windows forms' unhandled exceptions
Application.ThreadException+=new
System.Threading.ThreadExceptionEventHandler(Application_ThreadException);
Application.Run(new UIPStarter());
}
// CLR unhandled exception
private static void OnUnhandledException(Object sender,
UnhandledExceptionEventArgs e)
{
HandleUnhandledException(e);
}
// Windows Forms unhandled exception
private static void Application_ThreadException(object sender,
System.Threading.ThreadExceptionEventArgs e)
{
HandleUnhandledException(e);
}
static void HandleUnhandledException(Object o)
{
Exception e = o as Exception;
BaseForm.ReportException(e);
MessageBox.Show("An unhandled exception occurred and the application is
shutting down.");
Application.Exit();
}
}
}