Merge pull request #4998 from kumpera/fix_56684
[mono.git] / mono / tests / bug-46661.cs
1 using System;
2 using System.Linq;
3 using System.IO;
4
5 namespace ExceptionFilterTestLauncher
6 {
7     class Program
8     {
9         public static object newObject = null;
10         public static bool SubTest(int i)
11         {
12             return newObject.GetHashCode() == i;
13         }
14
15         public static bool HandleException(Exception e)
16         {
17             return true;
18         }
19
20         public static bool Test2(int i)
21         {
22             bool test = true;
23             try
24             {
25                 test = SubTest(i);
26             }
27             catch (Exception e) when (!HandleException(e))
28             {
29             }
30             return test;
31         }
32
33         static void Main(string[] args)
34         {
35             try
36             {
37                 bool result = Test2(12345);
38             }
39             catch (Exception e)
40             {
41                 // Before bug 46661 was fixed, the when would cut the stack trace, so Test(int) wouldn't show up
42                 if(!e.StackTrace.Contains("SubTest"))
43                     throw new Exception("Stack trace doesn't reference SubTest function. Current stacktrace is " + e.StackTrace.ToString());
44                 else
45                     // Correct result
46                     Environment.Exit(0);
47             }
48             throw new Exception("Exception should have been caught!");
49         }
50     }
51 }