Merge pull request #3240 from alexanderkyte/aot_compiler_leaks
[mono.git] / mono / tests / exception18.cs
1 using System;
2 using System.Linq;
3
4 class C
5 {
6         static Exception e;
7
8         static void Throw ()
9         {
10                 try {
11                         int.Parse (null);
12                 } catch (Exception ex) {
13                         e = ex;
14                 }
15         }
16
17         static int FrameCount (Exception ex)
18         {
19                         string fullTrace = ex.StackTrace;
20                         string[] frames = fullTrace.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);
21
22                         // Ignore metadata
23                         frames = frames.Where (l => !l.StartsWith ("[")).ToArray ();
24
25                         return frames.Length;
26         }
27
28         public static void Main ()
29         {
30                 Throw ();
31
32                 try {
33                         throw e;
34                 } catch (Exception ex) {
35                         int frames = FrameCount (ex);
36                         if (frames != 1)
37                                 throw new Exception (String.Format("Exception carried {0} frames along with it when it should have reported one.", frames));
38                 }
39
40                 try {
41                         try {
42                                 int.Parse (null);
43                         } catch (Exception) {
44                                 throw;
45                         }
46                 } catch (Exception ex) {
47                         int frames = FrameCount (ex);
48                         if (frames != 4)
49                                 throw new Exception (String.Format("Exception carried {0} frames along with it when it should have reported four.", frames));
50                 }
51
52         }
53 }