没有合适的资源?快使用搜索试试~ 我知道了~
代码如下:using System;using System.Collections.Generic;using System.Linq; using System.Text;//2014.3.14namespace _6.异常{ class Program { static void Main(string[] args) { try { Console.WriteLine(“Convert之前”); int a = Convert.ToInt32(
资源详情
资源评论
资源推荐
c#异常处理示例分享异常处理示例分享
代码如下:
using System;
using System.Collections.Generic;
using System.Linq; using System.Text;
//2014.3.14
namespace _6.异常
{
class Program
{
static void Main(string[] args)
{
try
{
Console.WriteLine(“Convert之前”);
int a = Convert.ToInt32(Console.ReadLine());
Console.WriteLine(“Convert之后”);
}
catch (Exception ex)
{
Console.WriteLine(“输入错误:”+ex.Message+”异常堆栈:”+ex.StackTrace);
}
try
{
Console.WriteLine(“请输入你的年龄:”);
int s = Convert.ToInt32(Console.ReadLine());
string desc = GetAgeDesc(s);
Console.WriteLine(desc);
}
catch (Exception ex)
{
Console.WriteLine(“数据错误,”+ex.Message);
}
Console.ReadKey();
}
static string GetAgeDesc(int age)
{
if (age >= 0 && age <= 3)
{
return “婴幼儿”;
}
else if (age > 3 && age < 18)
{
return “青少年”;
}
else if (age >=18 && age < 60)
{
return “成年人”;
}
else if (age >= 60 && age < 100)
{
return “老年人”;
}
else
{
throw new Exception(“自己创建的ex.Message”);
}
}
}
}
您可能感兴趣的文章您可能感兴趣的文章:C# WebApi 异常处理解决方案C#异常处理总结及简单实例C#异常处理中try和catch语句及finally语句的
用法示例详解C#编程中异常的创建和引发以及异常处理解析C#中断言与异常的应用方式及异常处理的流程控制轻松学习C#的
异常处理C#异常处理的一些经验和技巧C#异常处理详解.NET(C#):Emit创建异常处理的方法C#异常处理的技巧和方法
weixin_38558246
- 粉丝: 5
- 资源: 956
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0