try-catch用法

时间:2015-05-03 14:57:03
【文件属性】:
文件名称:try-catch用法
文件大小:896B
文件格式:TXT
更新时间:2015-05-03 14:57:03
try-catch try { Console.Write("请输入整数x:"); int x = Convert.ToInt32(Console.ReadLine()); Console.Write("请输入整数y:"); int y = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("x/y={0}", x / y); }catch(DivideByZeroException e){ Console.WriteLine(e.Message); }catch(FormatException e1){ Console.WriteLine(e1.Message); Console.WriteLine("输入的数据格式不正确。"); }catch(Exception e2){ Console.WriteLine(e2.Message); }

网友评论