实例:
让用户输入一个数,然后求该数的倒数
根据用户输入内容的不同产生相应异常提示
1.除零异常
2.溢出异常
3.转换异常
4.其他未知异常
public static void RunSnippet()
{
Console.WriteLine("请输入一个整数:");
try
{
int myint=int.Parse(Console.ReadLine());
double mydouble=1.0/myint;
Console.WriteLine("该数的倒数是:"+mydouble);
}
catch(DivideByZeroException)
{
Console.WriteLine("产生除零异常");
}
catch(OverflowException)
{
Console.WriteLine("溢出异常");
}
catch(FormatException)
{
Console.WriteLine("转换异常");
}
catch(Exception)
{
Console.WriteLine("其他异常");
}
}
英雄联盟真好玩