抛出异常
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();
}
}

浙公网安备 33010602011771号