不带参数的抛出异常
public static void PrintArgs(string args)
{
try
{
try
{
if (args == null)
{
ArgumentNullException myEx = new ArgumentNullException("args");
throw myEx;//这里是抛出异常然后直接运行到Catch中。当Catch没有语句,则会中断程序。
}
Console.WriteLine(args);
}
catch (ArgumentNullException e)
{
Console.WriteLine("Message:{0}", e.Message);
throw;//不带参数的抛出异常。会跳到catch中区执行程序。
}
}
catch
{
Console.WriteLine("Other Catch:Handing an Exception");
}
}
static void Main(string[] args)
{
string s = null;
PrintArgs(s);
Console.ReadLine();
}

浙公网安备 33010602011771号