考虑以下 IL 代码:
.method public static void Main()
{
ldstr "Starts Here"
call void [mscorlib] System.Console::WriteLine(string)
.try {
ldstr "Try Me!"
call void [mscorlib] System.Console::WriteLine(string)
leave.s Done
}
catch [mscorlib] System.Exception {
ldstr "Catch Me!"
call void [mscorlib] System.Console::WriteLine(string)
leave.s Done
}
Done:
ldstr "Ends Here"
call void [mscorlib] System.Console::WriteLine(string)
ret
}
CLR 如何try
在 JIT 代码中定义块?本机代码如下所示:
...
00900076 8b0538214703 mov eax,dword ptr ds:[3472138h] ("Starts Here")
...
00900090 8b053c214703 mov eax,dword ptr ds:[347213Ch] ("Try Me!")
...
009000a2 eb1b jmp 009000bf ;// Done
009000a4 8945d4 mov dword ptr [ebp-2Ch],eax
009000a7 8b0540214703 mov eax,dword ptr ds:[3472140h] ("Catch Me!")
...
009000b8 e888293b73 call clr!JIT_EndCatch (73cb2a45)
009000bd eb00 jmp 009000bf ;// Done
;// Done:
009000bf 8b0544214703 mov eax,dword ptr ds:[3472144h] ("Ends Here")
...
009000d6 c3 ret
我们可以看到clr!JIT_EndCatch
,但是块的开始和结束在try
哪里?