2015年11月17日 星期二

C13_7 重發例外

using System;
namespace C13_7
{
    public class A
    {
        public void F()
        {
            try
            {
                int z = 0;
                int i = 100 / z;
            }
            catch (DivideByZeroException e)
            {
                //作出處理並拋出例外
                throw e;
            }
        }
    }
    public class Program
    {
        public static void Main()
        {
            A a = new A();
            try
            {
                a.F();
            }
            catch (Exception e)
            {
                Console.WriteLine("例外資訊:{0}",e);
            }
        }
    }
}

沒有留言: