一点建议, 不要把眼光只局限于语法方面或者文档的定义, 可以看看它的代码, 实际上, Abort()最终就是调用RaiseException()来引起软件异常, 然后Delphi的SEH处理代码对此作了特殊处理, 不弹出出错对话框, 下面是与此相关的少量代码, 俺随手写的, 欢迎指正!
// 自定义异常编码
const
LeaveException = $20000000;
// 扩展了的SEH节
type
PEstablisherFrame = ^TEstablisherFrame;
TEstablisherFrame = record
Prev: PEstablisherFrame;
Handler: Pointer;
SafeEip: DWORD; // 出错跳转地址
end;
// 异常回调返回值
type
TExceptionDisposition = DWORD;
const
ExceptionContinueExecution = 0;
ExceptionContinueSearch = 1;
ExceptionNestedException = 2;
ExceptionCollidedUnwind = 3;
// 线程异常回调
function ExceptHandler(var ExceptionRecord: TExceptionRecord; var EstablisherFrame: TEstablisherFrame;
var ContextRecord: TContext; DispatcherContext: Pointer): TExceptionDisposition; cdecl;
begin
if (ExceptionRecord.ExceptionCode = LeaveException) then
begin
ContextRecord.Eip := EstablisherFrame.SafeEip; // 跳到后面
ContextRecord.Esp := DWORD(@EstablisherFrame); // 恢复栈顶
Result := ExceptionContinueExecution; // 已经处理, 线程按ContextRecord继续执行
end else
Result := ExceptionContinueSearch; // 没有处理, 系统继续"询问"后面的SEH节点
end;
// 在调用线程引发一个软件异常
procedure _leave();
begin
RaiseException(LeaveException, 0, 0, nil)
end;
procedure TForm1.Button1Click(Sender: TObject);
asm
// 入口代码(保护现场)
PUSH EBP
PUSH EBX
PUSH ESI
PUSH EDI
// 异常保护( try )
PUSH OFFSET @@SafeEip // TEstablisherFrame.SafeEip := @@SafeEip;
PUSH OFFSET ExceptHandler // TEstablisherFrame.Handler := @ExceptHandler;
PUSH FS:[0] // TEstablisherFrame.Prev := TEB.ExceptionList;
MOV FS:[0], ESP // TEB.ExceptionList := @TEstablisherFrame;
// 弹出异常
CALL _leave
// 去除保护( except )
@@SafeEip:
POP FS:[0] // TEB.ExceptionList := TEstablisherFrame.Prev;
ADD ESP, TYPE Pointer * 2 // 恢复栈顶
// 出口代码(恢复现场)
POP EDI
POP ESI
POP EBX
POP EBP
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
_leave();
end;