异常--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("\n程序执行完毕...");
            }
            Console.ReadLine();
        }
    }

  

 

posted @ 2017-07-24 14:37  mCat  Views(140)  Comments(0Edit  收藏  举报