异常--try..catch

    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                object obj = null;
                int N = (int)obj;
            }
            catch(Exception ex)
            {
                Console.WriteLine("捕获异常:" + ex);
            }
            Console.ReadLine();
        }
    }

try...catch...finally  

    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                object obj = null;
                int N = (int)obj;
            }
            catch(Exception ex)
            {
                Console.WriteLine("捕获异常:" + ex);
            }
            finally//最后执行的语句
            {
                Console.WriteLine("
程序执行完毕...");
            }
            Console.ReadLine();
        }
    }

  

原文地址:https://www.cnblogs.com/my-cat/p/7228818.html