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

                }

            }

        }

    }

  • 相关阅读:
    设计模式相关,单例模式!
    混合App交互相关,jsBridge的原理
    Vue相关,插槽怎么用!
    Mysql相关,查询功能整理
    图文并茂讲解进程与线程
    线程与进程的区别及其通信方式
    算法,十进制数转任意进制数
    JavaScript,leetcode第198题,打家劫舍
    2.4G无线控制器附加AT2401C功放IC增加距离
    超低功耗WiFi :ESP8089
  • 原文地址:https://www.cnblogs.com/gyt-xtt/p/3639037.html
Copyright © 2011-2022 走看看