Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / mono / tests / unhandled-exception-5.cs
1 using System;
2 using System.Diagnostics;
3 using System.Threading;
4 using System.Threading.Tasks;
5
6 class CustomException : Exception
7 {
8 }
9
10 class Driver
11 {
12         static ManualResetEvent mre = new ManualResetEvent (false);
13
14         class FinalizedClass
15         {
16                 ~FinalizedClass ()
17                 {
18                         try {
19                                 throw new CustomException ();
20                         } finally {
21                                 mre.Set ();
22                         }
23                 }
24         }
25
26         /* expected exit code: 255 */
27         static void Main (string[] args)
28         {
29                 if (Environment.GetEnvironmentVariable ("TEST_UNHANDLED_EXCEPTION_HANDLER") != null)
30                         AppDomain.CurrentDomain.UnhandledException += (s, e) => {};
31
32                 new FinalizedClass();
33
34                 GC.Collect ();
35                 GC.WaitForPendingFinalizers ();
36
37                 if (!mre.WaitOne (5000))
38                         Environment.Exit (2);
39
40                 /* Give a chance to the finalizer thread to finish executing the exception unwinding
41                  * after the finally, before we exit with status 0 on the current thread */
42                 Thread.Sleep (1000);
43
44                 Environment.Exit (0);
45         }
46 }