Exemple #1
0
    public static void Main()
    {
        try {
            throw new Exception("Stacktrace with 1 frame");
        } catch (Exception e) {
            Console.WriteLine(e);
            Console.WriteLine("Stacktrace:");
            Console.WriteLine(new System.Diagnostics.StackTrace(e));
        }

        Catch(() => { throw new Exception("Stacktrace with 2 frames"); });

        Catch(() => ThrowException("Stacktrace with 3 frames", 1));

        Catch(() => ThrowException("Stacktrace with 4 frames", 2));

        Catch(() => {
            var message = "Stack frame with method overload using ref parameter";
            ThrowException(ref message);
        });

        Catch(() => {
            int i;
            ThrowException("Stack frame with method overload using out parameter", out i);
        });

        Catch(() => ThrowExceptionGeneric <double> ("Stack frame with 1 generic parameter"));

        Catch(() => ThrowExceptionGeneric <double, string> ("Stack frame with 2 generic parameters"));

        Catch(() => ThrowExceptionGeneric(12));

        Catch(() => InnerClass.ThrowException("Stack trace with inner class"));

        Catch(() => InnerGenericClass <string> .ThrowException("Stack trace with inner generic class"));

        Catch(() => InnerGenericClass <string> .ThrowException("Stack trace with inner generic class and method generic parameter", "string"));

        Catch(() => InnerGenericClass <string> .ThrowException <string> ("Stack trace with inner generic class and generic overload", "string"));

        Catch(() => InnerGenericClass <string> .InnerInnerGenericClass <int> .ThrowException("Stack trace with 2 inner generic class and generic overload"));

        Catch(() => InnerGenericClass <int> .InnerInnerGenericClass <string> .ThrowException("Stack trace with 2 inner generic class and generic overload"));

        Catch(() => {
            var d = new Dictionary <string, string> ();
            d.ContainsKey(null);              // ArgumentNullException
        });
    }
Exemple #2
0
    public static void Main()
    {
        try {
            throw new Exception("Stacktrace with 1 frame");
        } catch (Exception e) {
            Console.WriteLine(e);
            Console.WriteLine("Stacktrace:");
            Console.WriteLine(new System.Diagnostics.StackTrace(e));
        }

        Catch(() => { throw new Exception("Stacktrace with 2 frames"); });

        Catch(() => ThrowException("Stacktrace with 3 frames", 1));

        Catch(() => ThrowException("Stacktrace with 4 frames", 2));

        Catch(() => {
            var message = "Stack frame with method overload using ref parameter";
            ThrowException(ref message);
        });

        Catch(() => {
            int i;
            ThrowException("Stack frame with method overload using out parameter", out i);
        });

        Catch(() => ThrowExceptionGeneric <double> ("Stack frame with 1 generic parameter"));

        Catch(() => ThrowExceptionGeneric <double, string> ("Stack frame with 2 generic parameters"));

        Catch(() => ThrowExceptionGeneric(12));

        Catch(() => InnerClass.ThrowException("Stack trace with inner class"));

        Catch(() => InnerGenericClass <string> .ThrowException("Stack trace with inner generic class"));

        Catch(() => InnerGenericClass <string> .ThrowException("Stack trace with inner generic class and method generic parameter", "string"));

        Catch(() => InnerGenericClass <string> .ThrowException <string> ("Stack trace with inner generic class and generic overload", "string"));

        Catch(() => InnerGenericClass <string> .InnerInnerGenericClass <int> .ThrowException("Stack trace with 2 inner generic class and generic overload"));

        Catch(() => InnerGenericClass <int> .InnerInnerGenericClass <string> .ThrowException("Stack trace with 2 inner generic class and generic overload"));

        Catch(() => InnerGenericClass <int> .ThrowException("Stack trace with nested type argument", "string", null));

        Catch(() => {
            var d = new Dictionary <string, string> ();
            d.ContainsKey(null);              // ArgumentNullException
        });

        /*
         * The following test include ambiguous methods we can't resolve. Testing this is hard, so I'm leaving a test behind but disabling it for the time being
         * In this case the ambiguous methods are:
         *      public static void Foo<K> (int a, bool hard_crash, GenClass<T> arg, List<int> zz)
         *      public static void Foo<K> (int a, bool hard_crash, GenClass<T> arg, List<double> zz)
         *
         * The are ambiguous because the only difference is the instantiation on the last parameter which we can't
         * figure out from a stacktrace.
         */
        //Catch (() => ComplicatedTestCase.Run ());
    }
    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 {
            ThrowException("Stacktrace with 3 frames", 2);
        } catch (Exception e) {
            Console.WriteLine(e);
        }

        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 {
            ThrowExceptionGeneric <double> ("Stack frame with 1 generic parameter");
        } catch (Exception e) {
            Console.WriteLine(e);
        }

        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 {
            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);
        }
    }