C# try catch

            异常语句try catch finally

            try//保护执行里面的代码段,若其中一句有错误,直接跳转到catch
            {//不会管下面的内容
                Console.Write("请输入一个整数");
                int a = int.Parse(Console.ReadLine());
                Console.WriteLine("hello");
            }
            catch //try中发现异常,直接执行,若try中无错,不执行
            {
                Console.WriteLine("输入有误!");
            }

            finally//不管上面有没有错,都需要执行!
            {
                Console.WriteLine("谢谢使用,再见!");
            }

 

posted @ 2016-03-12 16:35  Yao1101  阅读(260)  评论(0编辑  收藏  举报