.net2.0之杂七杂八(4)
来源:互联网 发布:快刀软件破解版 编辑:程序博客网 时间:2024/05/18 12:33
Managed Exception Handling
EH块紧跟在IL代码后(还记得方法体的结构吗),首先是一个EH头,EH头中包括Kind和DataSize两项。同样,EH头分small和fat,不同的是DataSize的大小,fat为3字节,而small为1字节。
Kind的可选值如下:
0x00:Reserved
0x01:EHTable(必须置位)
0x02:OptILTable(未使用)
0x40:FatFormat
0x80:MoreSects
EH头完了后,就是一串EH Clause Entries了。每个Entry的结构如下(汗,office 2007的制表功能还真不错J):
EH Clause Entry
Size in Small Clause
Size in Fat Clause
Flags
2
4
TryOffset
2
4
TryLength
1
4
HandlerOffset
2
4
HandlerLength
1
4
ClassToken/FilterOffset
4
4
怪了,怎么没有finally块呢?其实,块的种类可以根据Flags来区别。Flags可取的值如下:
0x0000:Then handler must be engaged if the type of exception object matches the type identified by the token specified in the ClassToken entry or any of this type’s descendants.
0x0001:A dedicated block of the IL code, called a filter, will process the exception and define whether the handler should be engaged.
0x0002:The handler will be engaged whether or not an exception has occurred.这便是finally了。
0x0004:The handler will be engaged if any exception occurs.这是fault块。
EH有两种声明方式,Label式和Scope式。后者是我们在ildasm反编译代码中看到的形式。还可以把两种混合起来使用。形式不一样,本质是相同地。下面看一个filter的label形式的例子(抄书的):
.try {
//Guarded code
…
leave KeepGoing
}
filter{
//here we decide whether we should invoke the actual handler
…
ldc.i4.1//OK, let’s invoke the handler
endfilter
}{
//actual handler code
…
leave KeepGoing
}
不同块中的椎栈变化如下表:
Block
进入时,椎栈…
退出时,椎栈…
try
为空
被抛弃
filter
包含Exception Object
1或0,用于endfilter进行判断
handler
包含Exception Object
被抛弃
fnally,fault
为空
被抛弃
rethrow只能用于catch块内,且不对椎栈进行操作。
四种不能被继承的异常类型:
InvalidProgramException
TypeInitializationException
Threading.ThreadAbortException
StackOverflowException
OK了,异常处理介绍就到这。
- .net2.0之杂七杂八(4)
- .net2.0之杂七杂八(1)
- .net2.0之杂七杂八(2)
- .net2.0之杂七杂八(3)
- .NET2.0之迭代器
- 杂七杂八之工作100207
- 网上资源之杂七杂八
- android 之杂七杂八
- 工作笔记之杂七杂八
- android 之杂七杂八
- android 之杂七杂八
- 实战之杂七杂八
- javascript之杂七杂八
- .NET2.0之泛型
- asp.net2.0之感.
- Asp.Net2.0之WebPart
- 杂七杂八
- 杂七杂八
- vi配置文件集合
- 也该写写东西了
- 07.01.08
- 走走逛逛,抬头看看,低头望望
- effective stl读书笔记 —— Item 3
- .net2.0之杂七杂八(4)
- 为什么英文的windows操作系统安装中文的软件会出现乱码?
- linux基本操作命令
- gcc profiling的工作原理
- 设计模式学习记录(设计要求-GRASP模式)
- A*路径寻找算法入门
- 深入A*算法
- 将 JavaScript 与 ASP.NET 2.0 配合使用
- 对象和类(一)