2 using System.Diagnostics;
3 using System.Threading;
4 using System.Threading.Tasks;
6 class CustomException : Exception
12 /* expected exit code: 255 */
13 static void Main (string[] args)
15 if (Environment.GetEnvironmentVariable ("TEST_UNHANDLED_EXCEPTION_HANDLER") != null)
16 AppDomain.CurrentDomain.UnhandledException += (s, e) => {};
18 ManualResetEvent mre = new ManualResetEvent (false);
20 var t = Task.Factory.StartNew (new Action (() => { try { throw new CustomException (); } finally { mre.Set (); } }));
22 if (!mre.WaitOne (5000))
28 } catch (AggregateException ae) {
29 Console.WriteLine (ae);
30 if (ae.InnerExceptions [0] is CustomException) {
31 /* expected behaviour */
32 Environment.Exit (255);
34 } catch (Exception ex) {
35 Console.WriteLine (ex);