2 using System.Collections.Generic;
4 class StackTraceDumper {
6 public static void Main ()
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));
16 Catch (() => {throw new Exception ("Stacktrace with 2 frames");});
18 Catch (() => ThrowException ("Stacktrace with 3 frames", 1));
20 Catch (() => ThrowException ("Stacktrace with 4 frames", 2));
23 var message = "Stack frame with method overload using ref parameter";
24 ThrowException (ref message);
29 ThrowException ("Stack frame with method overload using out parameter", out i);
32 Catch (() => ThrowExceptionGeneric<double> ("Stack frame with 1 generic parameter"));
34 Catch (() => ThrowExceptionGeneric<double,string> ("Stack frame with 2 generic parameters"));
36 Catch (() => ThrowExceptionGeneric (12));
38 Catch (() => InnerClass.ThrowException ("Stack trace with inner class"));
40 Catch (() => InnerGenericClass<string>.ThrowException ("Stack trace with inner generic class"));
42 Catch (() => InnerGenericClass<string>.ThrowException ("Stack trace with inner generic class and method generic parameter", "string"));
44 Catch (() => InnerGenericClass<string>.ThrowException<string> ("Stack trace with inner generic class and generic overload", "string"));
46 Catch (() => InnerGenericClass<string>.InnerInnerGenericClass<int>.ThrowException ("Stack trace with 2 inner generic class and generic overload"));
48 Catch (() => InnerGenericClass<int>.InnerInnerGenericClass<string>.ThrowException ("Stack trace with 2 inner generic class and generic overload"));
51 public static void Catch (Action action)
55 } catch (Exception e) {
57 Console.WriteLine (e);
58 Console.WriteLine ("Stacktrace:");
59 Console.WriteLine (new System.Diagnostics.StackTrace (e));
63 public static void ThrowException (string message)
65 throw new Exception (message);
68 public static void ThrowException (ref string message)
70 throw new Exception (message);
73 public static void ThrowException (string message, int i)
76 ThrowException (message, --i);
78 throw new Exception (message);
81 public static void ThrowException (string message, out int o)
83 throw new Exception (message);
86 public static void ThrowExceptionGeneric<T> (string message)
88 throw new Exception (message);
91 public static void ThrowExceptionGeneric<T> (T a1)
93 throw new Exception ("Stack frame with generic method overload");
96 public static void ThrowExceptionGeneric<T> (List<string> a1)
98 throw new Exception ("Stack frame with generic method overload");
101 public static void ThrowExceptionGeneric<T> (List<T> a1)
103 throw new Exception ("Stack frame with generic method overload");
106 public static void ThrowExceptionGeneric<T1,T2> (string message)
108 throw new Exception (message);
112 public static void ThrowException (string message)
114 throw new Exception (message);
118 class InnerGenericClass<T> {
119 public static void ThrowException (string message)
121 throw new Exception (message);
124 public static void ThrowException (string message, T arg)
126 Console.WriteLine ("Generic to string:" + arg.ToString());
127 throw new Exception (message);
130 public static void ThrowException<T1> (string message, T1 arg)
132 throw new Exception (message);
135 public class InnerInnerGenericClass<T2> {
136 public static void ThrowException (T message)
138 throw new Exception (message as string);
141 public static void ThrowException (T2 message)
143 throw new Exception (message as string);