zoukankan      html  css  js  c++  java
  • C#程序的异常处理

    异常处理机制是保证程序健壮性的重要手段。

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    
    namespace TryCatchFinall
    {
        class Program
        {
            static void Main(string[] args)
            {
                string str = "爱上C#编程!";                    //声明一个string类型的变量str
                object obj = str;                            //声明一个object类型的变量obj
                try                                    //使用try语句捕获异常
                {
                    int i = (int)obj;                            //将obj强制转换成int类型
                }
                catch (Exception ex)                        //处理try语句捕获到的异常
                {
                    Console.WriteLine(ex.Message);            //输出异常信息
                }
                finally                                    //finally语句
                {
                    Console.WriteLine("finally语句被执行,程序执行完毕...");        
                }
                Console.ReadLine();
            }
        }
    }
  • 相关阅读:
    CTSC2018滚粗记
    HNOI2018游记
    NOIWC 2018游记
    PKUWC2018滚粗记
    HNOI2017 游记
    NOIP2017题解
    [HNOI2017]抛硬币
    [HNOI2017]大佬
    NOIP难题汇总
    [NOI2013]树的计数
  • 原文地址:https://www.cnblogs.com/stringAdmin/p/7490500.html
Copyright © 2011-2022 走看看