using System;
+using System.Collections.Generic;
class StackTraceDumper {
- public static void Main () {
- // Stacktrace with no depth
+
+ public static void Main ()
+ {
+ try {
+ throw new Exception ("Stacktrace with 1 frame");
+ } catch (Exception e) {
+ Console.WriteLine (e);
+ }
+
+ try {
+ ThrowException ("Stacktrace with 2 frames");
+ } catch (Exception e) {
+ Console.WriteLine (e);
+ }
+
try {
- throw new Exception ();
+ ThrowException ("Stacktrace with 3 frames", 2);
} catch (Exception e) {
Console.WriteLine (e);
}
- // Stacktrace with depth of 1
+
+ try {
+ var message = "Stack frame with method overload using ref parameter";
+ ThrowException (ref message);
+ } catch (Exception e) {
+ Console.WriteLine (e);
+ }
+
+ try {
+ int i;
+ ThrowException ("Stack frame with method overload using out parameter", out i);
+ } catch (Exception e) {
+ Console.WriteLine (e);
+ }
+
try {
- ThrowException ();
+ ThrowExceptionGeneric<double> ("Stack frame with 1 generic parameter");
} catch (Exception e) {
Console.WriteLine (e);
}
- // Stacktrace with depth of 2
+
+ try {
+ ThrowExceptionGeneric<double,string> ("Stack frame with 2 generic parameters");
+ } catch (Exception e) {
+ Console.WriteLine (e);
+ }
+
+ try {
+ ThrowExceptionGeneric (12);
+ } catch (Exception e) {
+ Console.WriteLine (e);
+ }
+
+ try {
+ InnerClass.ThrowException ("Stack trace with inner class");
+ } catch (Exception e) {
+ Console.WriteLine (e);
+ }
+
+ try {
+ InnerGenericClass<string>.ThrowException ("Stack trace with inner generic class");
+ } catch (Exception e) {
+ Console.WriteLine (e);
+ }
+
try {
- ThrowException2 ();
+ InnerGenericClass<string>.ThrowException ("Stack trace with inner generic class and method generic parameter", "string");
} catch (Exception e) {
Console.WriteLine (e);
}
+
+ try {
+ InnerGenericClass<string>.ThrowException<string> ("Stack trace with inner generic class and generic overload", "string");
+ } catch (Exception e) {
+ Console.WriteLine (e);
+ }
+
+ try {
+ InnerGenericClass<string>.InnerInnerGenericClass<int>.ThrowException ("Stack trace with 2 inner generic class and generic overload");
+ } catch (Exception e) {
+ Console.WriteLine (e);
+ }
+
+ try {
+ InnerGenericClass<int>.InnerInnerGenericClass<string>.ThrowException ("Stack trace with 2 inner generic class and generic overload");
+ } catch (Exception e) {
+ Console.WriteLine (e);
+ }
+ }
+
+ public static void ThrowException (string message)
+ {
+ throw new Exception (message);
+ }
+
+ public static void ThrowException (ref string message)
+ {
+ throw new Exception (message);
+ }
+
+ public static void ThrowException (string message, int i)
+ {
+ if (i > 1)
+ ThrowException (message, --i);
+
+ throw new Exception (message);
+ }
+
+ public static void ThrowException (string message, out int o)
+ {
+ throw new Exception (message);
}
- public static void ThrowException () {
- Console.WriteLine ("Exception is not in the first line!");
- throw new Exception ();
+ public static void ThrowExceptionGeneric<T> (string message)
+ {
+ throw new Exception (message);
}
- public static void ThrowException2 () {
- ThrowException ();
+ public static void ThrowExceptionGeneric<T> (T a1)
+ {
+ throw new Exception ("Stack frame with generic method overload");
}
+ public static void ThrowExceptionGeneric<T> (List<string> a1)
+ {
+ throw new Exception ("Stack frame with generic method overload");
+ }
+
+ public static void ThrowExceptionGeneric<T> (List<T> a1)
+ {
+ throw new Exception ("Stack frame with generic method overload");
+ }
+
+ public static void ThrowExceptionGeneric<T1,T2> (string message)
+ {
+ throw new Exception (message);
+ }
+
+ class InnerClass {
+ public static void ThrowException (string message)
+ {
+ throw new Exception (message);
+ }
+ }
+
+ class InnerGenericClass<T> {
+ public static void ThrowException (string message)
+ {
+ throw new Exception (message);
+ }
+
+ public static void ThrowException (string message, T arg)
+ {
+ Console.WriteLine ("Generic to string:" + arg.ToString());
+ throw new Exception (message);
+ }
+
+ public static void ThrowException<T1> (string message, T1 arg)
+ {
+ throw new Exception (message);
+ }
+
+ public class InnerInnerGenericClass<T2> {
+ public static void ThrowException (T message)
+ {
+ throw new Exception (message as string);
+ }
+
+ public static void ThrowException (T2 message)
+ {
+ throw new Exception (message as string);
+ }
+ }
+ }
}
\ No newline at end of file
-System.Exception: Exception of type 'System.Exception' was thrown.
- at StackTraceDumper.Main () in StackTraceDumper.cs:7
-Exception is not in the first line!
-System.Exception: Exception of type 'System.Exception' was thrown.
- at StackTraceDumper.ThrowException () in StackTraceDumper.cs:27
- at StackTraceDumper.Main () in StackTraceDumper.cs:13
-Exception is not in the first line!
-System.Exception: Exception of type 'System.Exception' was thrown.
- at StackTraceDumper.ThrowException () in StackTraceDumper.cs:27
- at StackTraceDumper.ThrowException2 () in StackTraceDumper.cs:31
- at StackTraceDumper.Main () in StackTraceDumper.cs:19
+System.Exception: Stacktrace with 1 frame
+ at StackTraceDumper.Main () in StackTraceDumper.cs:9
+System.Exception: Stacktrace with 2 frames
+ at StackTraceDumper.ThrowException (System.String message) in StackTraceDumper.cs:97
+ at StackTraceDumper.Main () in StackTraceDumper.cs:15
+System.Exception: Stacktrace with 3 frames
+ at StackTraceDumper.ThrowException (System.String message, Int32 i) in StackTraceDumper.cs:110
+ at StackTraceDumper.ThrowException (System.String message, Int32 i) in StackTraceDumper.cs:108
+ at StackTraceDumper.Main () in StackTraceDumper.cs:21
+System.Exception: Stack frame with method overload using ref parameter
+ at StackTraceDumper.ThrowException (System.String& message) in StackTraceDumper.cs:102
+ at StackTraceDumper.Main () in StackTraceDumper.cs:28
+System.Exception: Stack frame with method overload using out parameter
+ at StackTraceDumper.ThrowException (System.String message, System.Int32& o) in StackTraceDumper.cs:115
+ at StackTraceDumper.Main () in StackTraceDumper.cs:35
+System.Exception: Stack frame with 1 generic parameter
+ at StackTraceDumper.ThrowExceptionGeneric[T] (System.String message) in StackTraceDumper.cs:120
+ at StackTraceDumper.Main () in StackTraceDumper.cs:41
+System.Exception: Stack frame with 2 generic parameters
+ at StackTraceDumper.ThrowExceptionGeneric[T1,T2] (System.String message) in StackTraceDumper.cs:140
+ at StackTraceDumper.Main () in StackTraceDumper.cs:47
+System.Exception: Stack frame with generic method overload
+ at StackTraceDumper.ThrowExceptionGeneric[T] (T a1) in StackTraceDumper.cs:125
+ at StackTraceDumper.Main () in StackTraceDumper.cs:53
+System.Exception: Stack trace with inner class
+ at StackTraceDumper+InnerClass.ThrowException (System.String message) in StackTraceDumper.cs:146
+ at StackTraceDumper.Main () in StackTraceDumper.cs:59
+System.Exception: Stack trace with inner generic class
+ at StackTraceDumper+InnerGenericClass`1[T].ThrowException (System.String message) in StackTraceDumper.cs:153
+ at StackTraceDumper.Main () in StackTraceDumper.cs:65
+Generic to string:string
+System.Exception: Stack trace with inner generic class and method generic parameter
+ at StackTraceDumper+InnerGenericClass`1[T].ThrowException (System.String message, T arg) in StackTraceDumper.cs:159
+ at StackTraceDumper.Main () in StackTraceDumper.cs:71
+System.Exception: Stack trace with inner generic class and generic overload
+ at StackTraceDumper+InnerGenericClass`1[T].ThrowException[T1] (System.String message, T1 arg) in StackTraceDumper.cs:164
+ at StackTraceDumper.Main () in StackTraceDumper.cs:77
+System.Exception: Stack trace with 2 inner generic class and generic overload
+ at StackTraceDumper+InnerGenericClass`1+InnerInnerGenericClass`1[T,T2].ThrowException (T message) in StackTraceDumper.cs:170
+ at StackTraceDumper.Main () in StackTraceDumper.cs:83
+System.Exception: Stack trace with 2 inner generic class and generic overload
+ at StackTraceDumper+InnerGenericClass`1+InnerInnerGenericClass`1[T,T2].ThrowException (T2 message) in StackTraceDumper.cs:175
+ at StackTraceDumper.Main () in StackTraceDumper.cs:89