通过两个catch语句进行捕获异常它们分别是ArgumentNullException异常和Exception异常代码如下
using;
MainClass
{
voidProcessString(str)
{
(strnull)
{
throwArgumentNullException;
}
}
voidMain
{
Console.WriteLine("输出结果为:");
try
{
str=null;
ProcessString(str);
}
catch(ArgumentNullExceptione)
{
Console.WriteLine("{0}Firstexception.",e.Message);
}
catch(Exceptione)
{
Console.WriteLine("{0}Secondexception.",e.Message);
}
}
}
最新评论