I added exception handling by:
AddVectoredExceptionHandler(1,@Handler);
How to tell if an exception was generated by hardware or by RaiseException() ?
var
ExceptionHex:LongInt;
ExceptionPtr:Pointer = nil;
procedure ShowExc;
begin
WriteLn(WideString('Exception 0x'+Hex8(ExceptionHex)+' at 0x'+HexI(Int64(ExceptionPtr))));
Halt;
end;
function Handler(Excep:PExceptionPointers):LongInt;
asm
MOV RAX,[RCX+8]
MOV RAX,[RAX+Context64.&RIP]
CMP [RAX].Byte,$CC
JNZ @Print
MOV RAX,[RCX+8]
INC [RAX+Context64.&RIP]
JMP @Quits
@Exits: XOR EAX,EAX // EXCEPTION_CONTINUE_SEARCH
RET
@Print: //
CMP [ExceptionPtr],0
JNZ @Exits
MOV RAX,[RCX+0]
MOV EAX,[RAX]
MOV [ExceptionHex],EAX
LEA RDX,[ShowExc]
MOV RAX,[RCX+8]
XCHG RDX,[RAX+Context64.&RIP]
MOV [ExceptionPtr],RDX
//
@Quits: MOV EAX,-1 // EXCEPTION_CONTINUE_EXECUTION
end;
procedure AddException; inline;
begin
if not IsDebuggerPresent then
AddVectoredExceptionHandler(1,@Handler);
end;