博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
异常(Exception)
阅读量:4316 次
发布时间:2019-06-06

本文共 2177 字,大约阅读时间需要 7 分钟。

 

  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             catch15             {16                 Console.WriteLine("ELSE Exception");17             }18             finally19             {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             finally19             {20                 if (fs != null)21                 {22                     fs.Close();23                     fs = null;24                 }25             }26         }
FileNotFoundException

 

  3、NullReferenceException

1         ///  2         /// 委托 3         ///  4         /// 委托参数 5         public delegate void Show(string str); 6  7         ///  8         /// 事件 9         /// 10         public static event Show ShowEvent;11 12         public static void Test2()13         {14             try15             {16                 Console.WriteLine(ShowEvent.GetInvocationList().Count());17             }18             catch (NullReferenceException)19             {20                 Console.WriteLine("NullReferenceException");21             }22         }
NullReferenceException

 

转载于:https://www.cnblogs.com/Jacob-Wu/p/5779186.html

你可能感兴趣的文章
文件转码重写到其他文件
查看>>
AC自动机模板
查看>>
python 基本语法
查看>>
git配置
查看>>
【hexo】01安装
查看>>
使用case语句给字体改变颜色
查看>>
JAVA基础-多线程
查看>>
面试题5:字符串替换空格
查看>>
JSP九大内置对象及四个作用域
查看>>
ConnectionString 属性尚未初始化
查看>>
数据结构-栈 C和C++的实现
查看>>
MySQL基本命令和常用数据库对象
查看>>
poj 1222 EXTENDED LIGHTS OUT(位运算+枚举)
查看>>
进程和线程概念及原理
查看>>
Lucene、ES好文章
查看>>
android 生命周期
查看>>
jquery--this
查看>>
MySQL 5.1参考手册
查看>>
TensorFlow安装流程(GPU加速)
查看>>
OpenStack的容器服务体验
查看>>