zoukankan      html  css  js  c++  java
  • C#的异常处理机制

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.IO;
    
    namespace codeTest
    {
    
        class Program
        {
            //C# 语言中的异常处理的基本语法,主要是 try, catch, throw 以及 finally.
            //Exception是所有异常的基类  Exception的性能不好  最好捕抓对应的异常如(NullReferenceException) z
            //这样可以对不同的异常做不同的处理 也可以把未知的异常暴露出来
            static void Main(string[] args)
            {
                try
                {
                    int x = 0;
                    int y = 100 / x;
                }
                catch (NullReferenceException e)
                {
                    Console.WriteLine(e.Message);
                }
                catch (ArgumentException e)
                {
                    Console.WriteLine(e.Message);
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
                finally
                {
                    //不管是否补抓到异常finally里面的代码都会运行
                }
    
    
    
                //手动抛出异常
                throw new NullReferenceException();
                throw new ArgumentException();
                throw new DirectoryNotFoundException();
            }
    
    
        }
    
    
    }
  • 相关阅读:
    新东西
    Xcode6新特性
    下载模拟器
    iOS定位和地图
    iOS,作死集锦
    ThreadLocal源码解析
    JSON Web令牌(JWT)介绍与使用
    docker已运行容器里的时区修改
    Docker图形界面管理
    ZooKeeper开机启动的俩种方式
  • 原文地址:https://www.cnblogs.com/lgxlsm/p/3023210.html
Copyright © 2011-2022 走看看