抛出异常

 public static void PrintArgs(string args)
        {
            try
            if (args == null)
            {
                ArgumentNullException myEx = new ArgumentNullException("args");
                throw myEx;//这里是抛出异常然后直接运行到Catch中。
            }
            Console.WriteLine(args);
        }
        catch (ArgumentNullException e)
        {

            Console.WriteLine("Message:{0}", e.Message);
        }
    }

    static void Main(string[] args)
    {
        string s = null;
        PrintArgs(s);
        PrintArgs("Hi,Three");
        Console.ReadLine();
    }
}

posted @ 2022-03-05 09:59  跨界专家  阅读(32)  评论(0)    收藏  举报