diff --git a/Source/AffineThreadPool.Test.cs b/Source/AffineThreadPool.Test.cs index 3080862..5c906f1 100644 --- a/Source/AffineThreadPool.Test.cs +++ b/Source/AffineThreadPool.Test.cs @@ -249,6 +249,19 @@ namespace Nuclex.Support { } + /// + /// Tests whether the afine thread pool's default exception handler works + /// as expected + /// + [Test] + public void TestDefaultExceptionHandler() { + Assert.Throws( + delegate() { + AffineThreadPool.ExceptionHandler(new ArrayTypeMismatchException("Test")); + } + ); + } + /// /// Verifies that the waiting work items count and active thread count are /// updated by the thread pool. diff --git a/Source/AffineThreadPool.cs b/Source/AffineThreadPool.cs index f828f3f..31d4234 100644 --- a/Source/AffineThreadPool.cs +++ b/Source/AffineThreadPool.cs @@ -165,6 +165,14 @@ namespace Nuclex.Support { } } + /// + /// Default handler used to respond to unhandled exceptions in ThreadPool threads + /// + /// Exception that has occurred + internal static void DefaultExceptionHandler(Exception exception) { + throw exception; + } + /// A thread worker function that processes items from the work queue private static void ProcessQueuedItems() { @@ -198,7 +206,7 @@ namespace Nuclex.Support { thread.IdealProcessor = hardwareThreadIndex; } #endif - + // Keep processing tasks indefinitely for(; ; ) { UserWorkItem workItem = getNextWorkItem(); @@ -231,7 +239,7 @@ namespace Nuclex.Support { return threads[index]; } } - + return null; } #endif @@ -264,7 +272,7 @@ namespace Nuclex.Support { } /// Delegate used to handle assertion checks in the code - public static volatile ExceptionDelegate ExceptionHandler; + public static volatile ExceptionDelegate ExceptionHandler = DefaultExceptionHandler; #if !XBOX360 /// Retrieves the calling thread's thread id