Bug 227 - ThreadPool ignores UnhandledException handler
Summary: ThreadPool ignores UnhandledException handler
Alias: None
Product: Runtime
Classification: Mono
Component: General ()
Version: unspecified
Hardware: PC Linux
: --- normal
Target Milestone: ---
Assignee: Gonzalo Paniagua Javier
Depends on:
Reported: 2011-08-08 08:51 UTC by Marek Safar
Modified: 2011-08-14 02:11 UTC (History)
1 user (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Marek Safar 2011-08-08 08:51:50 UTC
using System;
using System.Threading;

class C
	static ManualResetEvent caught = new ManualResetEvent (false);
	public static int Main ()
		var handler = new UnhandledExceptionEventHandler (CurrentDomain_UnhandledException);
		AppDomain.CurrentDomain.UnhandledException += handler;
		ThreadPool.QueueUserWorkItem (l => { throw new ApplicationException (); });

		try {
			if (!caught.WaitOne (10000))
				return 1;

			Console.WriteLine ("hit");
			return 0;
		} finally {
			AppDomain.CurrentDomain.UnhandledException -= handler;

	static void CurrentDomain_UnhandledException (object sender, UnhandledExceptionEventArgs e)
		if (e.ExceptionObject is ApplicationException)
			caught.Set ();

.NET prints hit
Mono terminates with error code 255
Comment 1 Gonzalo Paniagua Javier 2011-08-14 02:11:44 UTC
Fixed in master/41d9165 and mono-2-10/7de9996