Merge pull request #4998 from kumpera/fix_56684
[mono.git] / mono / tests / unhandled-exception-2.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         /* expected exit code: 255 */
13         static void Main (string[] args)
14         {
15                 if (Environment.GetEnvironmentVariable ("TEST_UNHANDLED_EXCEPTION_HANDLER") != null)
16                         AppDomain.CurrentDomain.UnhandledException += (s, e) => {};
17
18                 ManualResetEvent mre = new ManualResetEvent (false);
19
20                 var a = new Action (() => { try { throw new CustomException (); } finally { mre.Set (); } });
21                 var ares = a.BeginInvoke (null, null);
22
23                 if (!mre.WaitOne (5000))
24                         Environment.Exit (2);
25
26                 try {
27                         a.EndInvoke (ares);
28                         Environment.Exit (4);
29                 } catch (CustomException) {
30                         /* expected behaviour */
31                         Environment.Exit (255);
32                 } catch (Exception ex) {
33                         Console.WriteLine (ex);
34                         Environment.Exit (3);
35                 }
36
37                 Environment.Exit (5);
38         }
39 }