Merge pull request #2454 from tastywheattasteslikechicken/FixVtableAbort
[mono.git] / mono / tests / unhandled-exception-4.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 t = Task.Factory.StartNew (new Action (() => { try { throw new CustomException (); } finally { mre.Set (); } }));
21
22                 if (!mre.WaitOne (5000))
23                         Environment.Exit (2);
24
25                 try {
26                         t.Wait ();
27                         Environment.Exit (5);
28                 } catch (AggregateException ae) {
29                         Console.WriteLine (ae);
30                         if (ae.InnerExceptions [0] is CustomException) {
31                                 /* expected behaviour */
32                                 Environment.Exit (255);
33                         }
34                 } catch (Exception ex) {
35                         Console.WriteLine (ex);
36                         Environment.Exit (3);
37                 }
38
39                 Environment.Exit (6);
40         }
41 }