[mcs] Reset catch state variable after it has been checked. Fixes #54322
[mono.git] / mcs / tests / test-async-93.cs
1 using System;
2 using System.Threading.Tasks;
3  
4 public class Test
5 {
6         public static int Main()
7         {
8                 var t = new Test ();
9                 t.Entry().Wait();
10                 if (t.caughtCounter != 1)
11                         return 1;
12
13                 return 0;
14         }
15  
16         int caughtCounter;
17
18         async Task Entry()
19         {
20                 for (int i = 0; i < 5; ++i) {
21                         try {
22                                 var result = Func(i);
23                                 Console.WriteLine($"{i} result {result}");
24                         } catch (Exception e) {
25                                 await Nothing();
26                                 Console.WriteLine($"{i} caught");
27                                 ++caughtCounter;
28                         }
29                 }
30         }
31  
32         bool Func(int i)
33         {
34                 if (i == 0) {
35                         throw new Exception();
36                 } else {
37                         return true;
38                 }
39         }
40  
41         async Task Nothing()
42         {
43         }
44 }