Merge pull request #4998 from kumpera/fix_56684
[mono.git] / mcs / tests / test-ex-filter-04.cs
1 using System;
2 using System.Threading.Tasks;
3
4 class X
5 {
6         static Exception ex = new ApplicationException ();
7
8         public static int Main ()
9         {
10                 if (Test (5, null).Result != 5)
11                         return 1;
12
13                 try {
14                         Test (5, ex).Wait ();
15                         return 2;
16                 } catch (AggregateException ae) {
17                         if (ae.InnerException != ex)
18                                 return 3;
19                 }
20
21                 try {
22                         Test (15, ex).Wait ();
23                         return 4;
24                 } catch (AggregateException ae) {
25                         if (ae.InnerException != ex)
26                                 return 5;
27                 }
28
29                 try {
30                         TestGeneric (5).Wait ();
31                         return 10;
32                 } catch (AggregateException ae) {
33                         if (ae.InnerException != ex)
34                                 return 11;
35                 }
36                 
37                 try {
38                         TestGeneric (15).Wait ();
39                         return 12;
40                 } catch (AggregateException ae) {
41                         if (ae.InnerException != ex)
42                                 return 13;
43                 }
44
45                 return 0;
46         }
47
48         async static Task<int> Test (int x, Exception e)
49         {
50                 try {
51                         Console.WriteLine (x);
52                         if (e != null)
53                                 throw e;
54                 } catch (Exception) when (x != 15) {
55                         await Task.FromResult (0);
56                         throw;
57                 }
58
59                 return x;
60         }
61
62         async static Task<int> TestGeneric (int x)
63         {
64                 try {
65                         Console.WriteLine (x);
66                         throw ex;
67                 } catch when (x != 15) {
68                         await Task.FromResult (0);
69                         throw;
70                 }
71
72                 return x;
73         }
74 }