码迷,mamicode.com
首页 > Windows程序 > 详细

C# 的异常处理的基本语法

时间:2016-11-26 20:48:26      阅读:360      评论:0      收藏:0      [点我收藏+]

标签:运算   运算符   处理   style   null   rgs   error   except   rri   

 1         static void Main(string[] args)
 2         {
 3             int x = 0;
 4             try
 5             {
 6                 int y = 100 / x;
 7             }
 8             catch (Exception e)
 9             {
10                 Console.WriteLine(e.Message);
11                 //throw; // 丢出异常
12             }
13             finally
14             {
15                 Console.WriteLine("Anyway,we arrive here");
16             }
17             Console.ReadKey();
19         }

 2.C# 的异常类

1 var ae = new ArgumentException();//参数异常类
2 var ane = new ArgumentNullException();//参数为空异常
3 var aore = new ArgumentOutOfRangeException();//参数超过范围异常
4 var dne = new DirectoryNotFoundException();//IO异常 路径没有找到
5 var fne = new FileNotFoundException();//文件没有找到 
6 var ioe = new InvalidOperationException();//运算符异常
7 var nie = new NotImplementedException();//方法调用异常

3.C# 处理异常

if语句的逻辑执行要比exception执行快很多,那么在实际开发过程中一般在底层都会使用try catch,在业务最上面为了防止error导致业务崩溃,也会使用try catch。

C# 的异常处理的基本语法

标签:运算   运算符   处理   style   null   rgs   error   except   rri   

原文地址:http://www.cnblogs.com/lilb/p/6104881.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!