| 一、什么是异常?   程序运行时发生的错误。 二、异常处理的一般代码模式。   try{..可能发生异常的代码} catch{..对异常的处理} finally{...无论是否发生异常、是否捕获异常都会执行的代码}。 实例: 简单实例:  try中某句代码异常后,后面的代码不会执行,直接跳转到catch finally的使用:希望代码无论如何都要执行,就把代码放finally中         1、catch无法捕获异常,程序崩溃,但会在崩溃前执行finally 中的代码。       2、如果catch里发生了异常。。。。。。       3、catch中有return时,也会在return前执行。  
 class Program
    {
        static void Main(string[] args)
        {
            Person person = new Person();
            person = null;
            try
            {
                person.Name = "张三";
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                Console.WriteLine("$$$$$$$$$$");
            }
        }
    }
    public class Person
    {
        public string Name { get; set; }
    }   |