I have one question and one suggestion on exception handling.
1) The question is:
for what purpose in stack frame included the third dword?
try statement assembles like following:
push offset32 L1395_exception__hla_
push ebp
mov ebp,
push dword ptr // <<----------------------------------- what purpose of this?
mov ebp,
push offset32 HWexcept__hla_
push dword ptr
mov dword ptr , esp
i debug some examples and did not found any usage of this dword in stack.

also if HardwareException__hla_ procedure can not handle exception it executes such a code:
add esp,4
mov eax,1
ret
in my Windows 2000 Prof construction like
try
w.RaiseException($1024,w.EXCEPTION_CONTINUABLE,0,NULL);
anyexception
endtry
this last ret in HardwareException__hla_ returns to something bad and raises hardwhere access violation
that anyexception -- endtry block handles

2) the suggestion is:
to enhance exception handling mechanism with delphi-like
try -- finally -- endtry block
i think that it can be very useful construction
Posted on 2003-11-24 05:52:19 by Elohim Meth
Originally posted by Elohim Meth
I have one question and one suggestion on exception handling.
1) The question is:
for what purpose in stack frame included the third dword?
try statement assembles like following:
push offset32 L1395_exception__hla_
push ebp
mov ebp,
push dword ptr // <<----------------------------------- what purpose of this?
mov ebp,
push offset32 HWexcept__hla_
push dword ptr
mov dword ptr , esp
i debug some examples and did not found any usage of this dword in stack.



This is for unwinding nested exceptions. It is a pointer to the last stack
frame containing a SEH record.


also if HardwareException__hla_ procedure can not handle exception it executes such a code:
add esp,4
mov eax,1
ret

Yes, this is the standard Windows policy for exceptions an SEH doesn't handle.


in my Windows 2000 Prof construction like
try
w.RaiseException(24,w.EXCEPTION_CONTINUABLE,0,NULL);
anyexception
endtry
this last ret in HardwareException__hla_ returns to something bad and raises hardwhere access violation
that anyexception -- endtry block handles


Ouch!
Try..Endtry does not handle system exceptions other than the hardware exceptions.
If you're going to use RaiseException to raise a non-standard Windows exception,
then you've got to provide your own SEH exception handler for it. (or else modify
the hwExcepts.masm file in the HLA Standard Library sources to handle the exception
you've raised with this API call).

For user-defined exceptions, you should use the HLA "raise" statement, e.g.,

raise( 24 );

Note that HLA adds some additional information to the SEH frame in order to allow the HLA run-time system to determine if an SEH frame was created by HLA or not. Other than the predefined "hardware" exceptions, HLA tends to ignore other exceptions in the system. So if you've got code raising an exception outside of HLA, you may need to provide your own version of the hwExcepts library routine to deal with it.



2) the suggestion is:
to enhance exception handling mechanism with delphi-like
try -- finally -- endtry block
i think that it can be very useful construction


Yeah it would.

In the meantime, you can use this:

try
<<protected code>>
anyexception
endtry
<< code that would go in the finally section>>

Cheers,
Randy Hyde
Posted on 2003-11-24 17:58:21 by rhyde
Thanks for reply,Mr Randall!

--------------------------------------------
try
<<protected code>>
anyexception
endtry
<< code that would go in the finally section>>
--------------------------------------------
this is not the same as try--finally-end because this construction handles all exceptions and
does not passes them any further.

i wrote and tested in some cases one macro that simulates try--finally-end construction in Delphi.
It may be of some use:

#macro guard:
lbl_Handler;
pushd(&lbl_Handler);
#asm
push ebp
push 0
push OFFSET HWexcept__hla_
push DWORD PTR fs:[0]
mov DWORD PTR fs:[0],esp
#endasm

#keyword unprotect;
#asm
mov esp,DWORD PTR fs:[0]
pop DWORD PTR fs:[0]
add esp,8
pop ebp
add esp,4
#endasm

#keyword finally;
lbl_Handler:
sub(4,esp);
push(eax);

#terminator endguard:
lbl_NoExcept;
pop(eax);
cmp((type dword ),&lbl_Handler);
jne lbl_NoExcept;
raise(eax);
lbl_NoExcept:
unprotect
#endmacro;
Posted on 2003-11-25 10:19:13 by Elohim Meth