现在的位置: 首页 > 综合 > 正文

从 except … end 跳回 try … 的例子

2013年02月14日 ⁄ 综合 ⁄ 共 819字 ⁄ 字号 评论关闭
从 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;

 

抱歉!评论已关闭.