zoukankan      html  css  js  c++  java
  • 异常(Exception)

      1、IOException

     1 public static void Test1()
     2         {
     3             FileStream fs = null;
     4             try
     5             {
     6                 fs = new FileStream("d:\file.txt", FileMode.Open);
     7                 fs.ReadByte();
     8                 Console.WriteLine("OK");
     9             }
    10             catch (IOException)
    11             {
    12                 Console.WriteLine("IOException");
    13             }
    14             catch
    15             {
    16                 Console.WriteLine("ELSE Exception");
    17             }
    18             finally
    19             {
    20                 if (fs != null)
    21                 {
    22                     fs.Close();
    23                     fs = null;
    24                 }
    25             }
    26         }
    IOException

      2、FileNotFoundException 继承自 IOException

     1         public static void Test1()
     2         {
     3             FileStream fs = null;
     4             try
     5             {
     6                 fs = new FileStream("d:\file.txt", FileMode.Open);
     7                 fs.ReadByte();
     8                 Console.WriteLine("OK");
     9             }
    10             catch (FileNotFoundException)
    11             {
    12                 Console.WriteLine("FileNotFoundException");
    13             }
    14             catch (IOException)
    15             {
    16                 Console.WriteLine("IOException");
    17             }
    18             finally
    19             {
    20                 if (fs != null)
    21                 {
    22                     fs.Close();
    23                     fs = null;
    24                 }
    25             }
    26         }
    FileNotFoundException

      3、NullReferenceException

     1         /// <summary>
     2         /// 委托
     3         /// </summary>
     4         /// <param name="str">委托参数</param>
     5         public delegate void Show(string str);
     6 
     7         /// <summary>
     8         /// 事件
     9         /// </summary>
    10         public static event Show ShowEvent;
    11 
    12         public static void Test2()
    13         {
    14             try
    15             {
    16                 Console.WriteLine(ShowEvent.GetInvocationList().Count());
    17             }
    18             catch (NullReferenceException)
    19             {
    20                 Console.WriteLine("NullReferenceException");
    21             }
    22         }
    NullReferenceException
  • 相关阅读:
    linux上部署docker+tomcat服务,并部署项目
    docker使用Dockerfile把springboot项目jar包生成镜像并运行
    springboot配置log4j
    mysql常用函数
    java处理csv文件上传示例
    中国城市区号脚本-mysql
    java微信公众号支付示例
    java导出csv格式文件
    mysql时间相加函数DATE_ADD()
    centos分区
  • 原文地址:https://www.cnblogs.com/Jacob-Wu/p/5779186.html
Copyright © 2011-2022 走看看