Esempio n. 1
0
        static void Method2()
        {
            ClassShouldDisposeBase c = null;

            try
            {
                c = new ClassShouldDisposeBase("Method2");
            }
            finally
            {
                c.Dispose();
            }
        }
Esempio n. 2
0
        static void Method3()
        {
            ClassShouldDisposeBase c = null;

            try
            {
                c = new ClassShouldDisposeBase("Method3");
                Method4();
            }
            catch
            {
                Console.WriteLine("在Mehod3 中捕獲異常");
            }
            finally
            {
                c.Dispose();
            }
        }
Esempio n. 3
0
        static void Method4()
        {
            ClassShouldDisposeBase c = null;

            try
            {
                c = new ClassShouldDisposeBase("Method4");
                throw new Exception();
            }
            catch
            {
                Console.WriteLine("在Mehod4 中捕獲異常");
                throw;
            }
            finally
            {
                c.Dispose();
            }
        }