程序如下:public class Mod
    {
        static void F()
        {
            try
            {
                G();
            }
            catch (Exception e)
            {
                Console.WriteLine("exception in F:" + e.Message);
                e = new Exception("F");
                throw;
            }
        }
        static void G()
        {
            throw new Exception("G");
        }        static void Main()
        {
            try
            {
                F();
            }
            catch (Exception e)
            {
                Console.WriteLine("exception in main:" + e.Message);
            }
                    }
    }在F方法里面作了这个
e = new Exception("F");
为什么输入第二个异常时还是输出G呢?

解决方案 »

  1.   

    public class Mod
        {
            static void F()
            {
                try
                {
                    G();
                }
                catch (Exception e)
                {
                    Console.WriteLine("exception in F:" + e.Message);
                    throw new Exception("F");
                }
            }
            static void G()
            {
                throw new Exception("G");
            }        static void Main()
            {
                try
                {
                    F();
                }
                catch (Exception e)
                {
                    Console.WriteLine("exception in main:" + e.Message);
                }
                        }
        }