zoukankan      html  css  js  c++  java
  • 异常实例

    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");

                }

            }

        }

    }

  • 相关阅读:
    [NSURL initFileURLWithPath:]: nil string parameter 错误的解决方案
    Parser Error Message: Could not load type 错误原因
    C# DropDownList做友情链接打开新窗口
    前两天去A公司面试,面试管问的题目一下子闷了。很郁闷。重新答题。在这里分享一下
    获取枚举描述信息(Description)
    生成实体层的界面(webForm1.aspx)代码
    java中Filter 技术
    hdu_1332&poj_1102_LCDisplay
    hdu_1997_汉诺塔VII
    hdu_1134_Game of Connections_卡特兰数列
  • 原文地址:https://www.cnblogs.com/gyt-xtt/p/3639037.html
Copyright © 2011-2022 走看看