Merge pull request #1936 from esdrubal/DotNetRelativeOrAbsolute
[mono.git] / mcs / tools / mono-symbolicate / Test / StackTraceDumper.cs
1 using System;
2 using System.Collections.Generic;
3
4 class StackTraceDumper {
5
6         public static void Main ()
7         {
8                 try {
9                         throw new Exception ("Stacktrace with 1 frame");
10                 } catch (Exception e) {
11                         Console.WriteLine (e);
12                         Console.WriteLine ("Stacktrace:");
13                         Console.WriteLine (new System.Diagnostics.StackTrace(e));
14                 }
15
16                 Catch (() => {throw new Exception ("Stacktrace with 2 frames");});
17
18                 Catch (() => ThrowException ("Stacktrace with 3 frames", 1));
19
20                 Catch (() => ThrowException ("Stacktrace with 4 frames", 2));
21
22                 Catch (() => {
23                         var message = "Stack frame with method overload using ref parameter";
24                         ThrowException (ref message);
25                 });
26
27                 Catch (() => {
28                         int i;
29                         ThrowException ("Stack frame with method overload using out parameter", out i);
30                 });
31
32                 Catch (() => ThrowExceptionGeneric<double> ("Stack frame with 1 generic parameter"));
33
34                 Catch (() => ThrowExceptionGeneric<double,string> ("Stack frame with 2 generic parameters"));
35
36                 Catch (() => ThrowExceptionGeneric (12));
37
38                 Catch (() => InnerClass.ThrowException ("Stack trace with inner class"));
39
40                 Catch (() => InnerGenericClass<string>.ThrowException ("Stack trace with inner generic class"));
41
42                 Catch (() => InnerGenericClass<string>.ThrowException ("Stack trace with inner generic class and method generic parameter", "string"));
43
44                 Catch (() => InnerGenericClass<string>.ThrowException<string> ("Stack trace with inner generic class and generic overload", "string"));
45
46                 Catch (() => InnerGenericClass<string>.InnerInnerGenericClass<int>.ThrowException ("Stack trace with 2 inner generic class and generic overload"));
47
48                 Catch (() => InnerGenericClass<int>.InnerInnerGenericClass<string>.ThrowException ("Stack trace with 2 inner generic class and generic overload"));
49         }
50
51         public static void Catch (Action action)
52         {
53                 try {
54                         action ();
55                 } catch (Exception e) {
56                         Console.WriteLine();
57                         Console.WriteLine (e);
58                         Console.WriteLine ("Stacktrace:");
59                         Console.WriteLine (new System.Diagnostics.StackTrace (e));
60                 }
61         }
62
63         public static void ThrowException (string message)
64         {
65                 throw new Exception (message);
66         }
67
68         public static void ThrowException (ref string message)
69         {
70                 throw new Exception (message);
71         }
72
73         public static void ThrowException (string message, int i)
74         {
75                 if (i > 1)
76                         ThrowException (message, --i);
77
78                 throw new Exception (message);
79         }
80
81         public static void ThrowException (string message, out int o)
82         {
83                 throw new Exception (message);
84         }
85
86         public static void ThrowExceptionGeneric<T> (string message)
87         {
88                 throw new Exception (message);
89         }
90
91         public static void ThrowExceptionGeneric<T> (T a1)
92         {
93                 throw new Exception ("Stack frame with generic method overload");
94         }
95
96         public static void ThrowExceptionGeneric<T> (List<string> a1)
97         {
98                 throw new Exception ("Stack frame with generic method overload");
99         }
100
101         public static void ThrowExceptionGeneric<T> (List<T> a1)
102         {
103                 throw new Exception ("Stack frame with generic method overload");
104         }
105
106         public static void ThrowExceptionGeneric<T1,T2> (string message)
107         {
108                 throw new Exception (message);
109         }
110
111         class InnerClass {
112                 public static void ThrowException (string message)
113                 {
114                         throw new Exception (message);
115                 }
116         }
117
118         class InnerGenericClass<T> {
119                 public static void ThrowException (string message)
120                 {
121                         throw new Exception (message);
122                 }
123
124                 public static void ThrowException (string message, T arg)
125                 {
126                         Console.WriteLine ("Generic to string:" + arg.ToString());
127                         throw new Exception (message);
128                 }
129
130                 public static void ThrowException<T1> (string message, T1 arg)
131                 {
132                         throw new Exception (message);
133                 }
134
135                 public class InnerInnerGenericClass<T2> {
136                         public static void ThrowException (T message)
137                         {
138                                 throw new Exception (message as string);
139                         }
140
141                         public static void ThrowException (T2 message)
142                         {
143                                 throw new Exception (message as string);
144                         }
145                 }
146         }
147 }