C#入门11.7_本章小结及任务实施
2016-09-05 21:33
253 查看
实例:
让用户输入一个数,然后求该数的倒数
根据用户输入内容的不同产生相应异常提示
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("其他异常");
}
}英雄联盟真好玩
让用户输入一个数,然后求该数的倒数
根据用户输入内容的不同产生相应异常提示
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("其他异常");
}
}英雄联盟真好玩
相关文章推荐
- C#入门4.9——本章小结及任务实施
- C#入门7.12——本章小结及任务实施
- C#入门10.7——本章小结及任务实施
- C#入门6.18——本章总结及任务实施
- C#入门8.10——本章小结及任务实施
- C#入门1.7——本章总结及任务实施
- C#入门9.14——本章小结及任务实施
- C#4.0入门 第二章 任务并行库—第一页 只使用双核(转)
- C#4.0入门 第二章 任务并行库—第三页 性能的差异(转)
- Visual Studio 2005入门 之 C#基本语法 小结考试[视频]
- 软件合作开发:2012年年底给苏州工业园区某家软件企业实施C#.NET软件开发系统框架的经验小结
- C#入门3.5——本章总结及任务实施
- C#4.0入门 第二章 任务并行库—第二页 活用了内核吗?(转)
- C#入门2.4——本章小结
- Visual Studio 2005入门 之 C#基本语法 小结考试[视频]
- 软件合作开发:2012年年底给苏州工业园区某家软件企业实施C#.NET软件开发系统框架的经验小结
- 终于把《ASP.NET 1.1入门经典—— VISUAL C# .NET 2003编程篇》买回来了
- C#网络编程入门3
- (转载)自己动手用c#写控件 + 自己小结
- C# 特性(Attribute)入门(一)