从 except ... end 跳回 try ... 的例子

来源:互联网 发布:java 国内 大牛博客 编辑:程序博客网 时间:2024/05/16 11:16
从 except ... end 跳回 try ... 的例子

//=====================================================================
// MicroTip#7 从 except ... end 跳回 try ... 的例子
// Http://www.cnpack.org
// Written by SkyJacker 2007.05.17
// QQ Discuss Group: 130970
// 欢迎讨论 Win/Delphi SEH, QQ: 6705517  MSN&EMail: HeMiaoYu@gmail.com
//=====================================================================

函数流程:
try
  ProcA  <----+
except        |
  ProcB   ----+
end;
流程描述: ProcA 发生异常后,进入异常处理函数 ProcB,然后再从 ProcB 跳回 ProcA。

下面函数演示:从异常处理函数返回到异常发生处的下一条指令。

procedure ExceptToTry;
var
  MyAddr: Cardinal;
  sTitle: string;
  sCaption: string;
begin
  sTitle := 'Test';
  sCaption := 'Info';
  try
    asm
      call @CurrAddr;
      @CurrAddr:
      pop MyAddr // 获得本条指令的地址
      xor ecx, ecx
      idiv ecx
      push 0
      push sCaption
      push sTitle
      push 0
      Call MessageBox
    end;
  except
    asm
      mov eax, [MyAddr]
      add eax, 7
      jmp eax
    end;
  end;
end;
 
原创粉丝点击