using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace catch_finally_test
{
    class Program
    {
        static void Main()
        {
            try
            {
                Console.WriteLine("执行测试程序开始");
                throw new NullReferenceException();
            }
            catch (NullReferenceException c)
            {
                Console.WriteLine("捕获异常1", c);
            }
            catch
            {
                Console.WriteLine("捕获异常2");
            }
            finally                  //无论是否出现异常都会执行finally块
            {
                Console.WriteLine("执行finally程序块");
            }
        }
    }
}


本文转载:CSDN博客