码迷,mamicode.com
首页 > Windows程序 > 详细

C#异常

时间:2015-02-06 20:26:44      阅读:224      评论:0      收藏:0      [点我收藏+]

标签:

/*异常:
 * Date: 2015/2/6
 * Time: 18:54
 * 
 * To change this template use Tools | Options | Coding | Edit Standard Headers.
 */
using System;

namespace Exception
{
    class Program
    {
        
        public static void Main(string[] args)
        {
            // TODO: Implement Functionality Here
            int result=0;
            Console.WriteLine("Please input your age:");
            string ageText=Console.ReadLine();
            
            try
            {
                int age=int.Parse(ageText);
                Console.WriteLine(age*12);
            }
            catch(FormatException)
            {
                Console.WriteLine("The age entered,{0},is not valid",ageText);
                result=1;
//                throw new System.Exception("error:format is error");
            }
            
            catch(System.Exception exception)
            {
                Console.WriteLine("Unexpected error:{0}",exception.Message);
            }
            finally
            {
                Console.WriteLine("Goodbye");
            }
            Console.ReadKey(true);
        }
    }
}

 

C#异常

标签:

原文地址:http://www.cnblogs.com/vivieryuan/p/4277926.html

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