Hello,
here an simple example for nesting:
@exh_nesting TEXTEQU <0>
@TRY_BEGIN MACRO
LOCAL lbl,lbl2
@exh_nesting TEXTEQU %@exh_nesting + 1
% @exh_lbl_&@exh_nesting& TEXTEQU <lbl>
% @exh_ne_lbl_&@exh_nesting& TEXTEQU <lbl2>
ASSUME FS:NOTHING
pushad ; Save Current State
push lbl ; pNext
push dword ptr fs:[0] ; Install New Handler
mov dword ptr fs:[0], esp
ENDM
@TRY_EXCEPT MACRO
LOCAL lbl
% jmp @exh_ne_lbl_&@exh_nesting& ; No Exception Occured, so jump over
% @exh_lbl_&@exh_nesting&:
; unwinde code: ignore the failing code
mov eax,[esp+12]
mov [eax].CONTEXT.regEip,lbl
xor eax,eax
db 0c3h ; RET 0; to avoid problems with PROC's epilogue
lbl:
pop dword ptr fs:[0] ; Restore Old Exception Handler
add esp,4
popad ; Restore Old State
ENDM
@TRY_END MACRO Handler
LOCAL lbl
jmp lbl ; Exception was handled by @TRY_EXCEPT
% @exh_ne_lbl_&@exh_nesting&: ; No Exception Occured
pop dword ptr fs:[0] ; Restore Old Exception Handler
add esp, 32 + 4 ; ESP value before SEH was set. 32 for pushad and ...
lbl: ; ...4 for push offset Handler. (No Restore State)
@exh_nesting TEXTEQU %@exh_nesting - 1
ENDM ; Exception has been handled, or no exception occuredtest:
@TRY_BEGIN
print "0",13,10
@TRY_BEGIN
print "n1",13,10
xor ecx,ecx
div ecx
@TRY_EXCEPT
print "nexp",13,10
@TRY_END
xor eax,eax
mov eax,[eax]
@TRY_EXCEPT
print "1",13,10
@TRY_END