[Mono-dev] ThreadPool unhandled exceptions
Thad Thompson
TThompson at Nucsafe.com
Wed Dec 23 14:27:01 EST 2009
Hi,
I know this has been raised a few times in the past (bugs 332206,
334265, and 435127) but I've looked high and low for a workaround and
just can't seem to find it. Is there any way to catch, trap, log, crash,
or in any way be notified of an unhandled exception from a ThreadPool
thread? My apologies in advance if I've overlooked something basic.
Thanks,
-Thad
Example:
---------------------------------------------------------------------
namespace MonoExceptions
{
class MainClass
{
public static void Main (string[] args)
{
try
{
AppDomain.CurrentDomain.UnhandledException += (a,b) =>
{ Console.WriteLine("UnhandledException !"); };
System.Threading.ThreadPool.QueueUserWorkItem ( (a) =>
{
Console.WriteLine("About to throw an exception");
throw new Exception("I'd really like to catch
this");
});
System.Threading.Thread.Sleep(5000);
Console.WriteLine("Application Complete");
}
catch(Exception ex)
{
Console.WriteLine("Caught exception in Main: " +
ex.Message);
}
}
}
}
---------------------------------------------------------------------
Output:
About to throw an exception
Application Complete
More information about the Mono-devel-list
mailing list