码迷,mamicode.com
首页 > 其他好文 > 详细

20141017--异常语句try-catch

时间:2014-10-17 15:16:37      阅读:118      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   ar   使用   sp   div   

 1             //try-catch 尝试(try)-抓获(catch)
 2             try//尝试,保护起来,使程序出错也能执行
 3             {  //确定不会出错时不要用try,当不确定时使用try-catch可以捕获错误,
 4                 int i = int.Parse(Console.ReadLine());
 5                 Console.WriteLine("没有异常");
 6             }
 7             catch (Exception)//这里捕获错误,有错误才执行
 8             {
 9                 Console.WriteLine("对不起,程序出错了,");
10             }
11             finally//不管有没有错最后都执行
12             {
13                 Console.WriteLine("感谢使用");
14             }
15             Console.ReadLine();

bubuko.com,布布扣

20141017--异常语句try-catch

标签:style   blog   http   color   io   ar   使用   sp   div   

原文地址:http://www.cnblogs.com/Tirisfal/p/4030992.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!