C#的异常
2014-03-10 13:11
344 查看
感觉跟c++没什么不同
System.Exception 异常的基类
异常包含两种类型
SystemException
ApplicationException
Message和InnerException比较重要
System.Exception类包含3个方法
常用的异常类
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace testUnNormal { class Program { static void Main(string[] args) { int[] arr = new int[15]; try { int a = 0; int b = 50 / a; /* byte b = 10; b = checked((byte)(b+2000)); */ /* * string str = "abcdefd+10"; * int i = -1; * i = Int32.Parse(str);//这个会被 System.FormatException 捕获 */ } catch(System.FormatException ex) { Console.WriteLine(ex.Message); } catch (System.Exception ex) { Console.WriteLine(ex.Message); } finally { //始终运行 Console.WriteLine("hello" + arr.ToString()); } Console.ReadLine(); } } }
System.Exception 异常的基类
异常包含两种类型
SystemException
ApplicationException
Message和InnerException比较重要
System.Exception类包含3个方法
GetBaseException() | 获取异常的根Exception对象 |
GetObjectData() | 获取与异常相关的SerializationInfo属性的值 |
GetType() | 获取当前实例的运行时类型 |
相关文章推荐
- c# winform 获取当前程序运行根目录
- 记录1:c#的文件选择对话框
- C#实现插入排序
- C# winform DataGridView 行全选反选
- c#程序删除自身代码示例分享
- c#的事件
- C#构造函数里的base和this的区别
- C#中的 IList, ICollection ,IEnumerable 和 IEnumerator
- C# WebBrowser控件实现定时模拟按钮点击
- C#之读取XML文件并显示在textbox中
- 浅谈C#中的枚举
- C#读取Excel数据操作大全
- c#的delegate示例代码
- C#:MapControl基本操作代码整理
- [C#] Byte[]、Image、Bitmap 之间的相互转换
- C#控件 常用操作
- C#获取不同分辨率
- C#之 CS开发常用功能
- C#语言学习笔记
- C#委托之 Action<T>委托