Forum > Windows

Intercepting exceptions in a dll

(1/1)

DenReq:
Hello,

I hesitated to put this post in the "beginners" section.

I am trying to set up a Win32 DLL to intercept all the various exceptions and errors that can occur, including in threads.

Currently I'm failing completely, and I think my inexperience with FPC is most likely the cause. Something that seems pretty basic to me like setting up an ErrorProc procedure, which is supposed to convert a call to RunError into an exception, doesn't work at all: the set up function is obviously not called and the program execution abruptly terminates. This seems to me to be a sign that I'm missing something as big as a house.

The minimal code is here. To me the call to TestExceptionRunError from the host application should produce an exception intercepted by the try except block, not terminate immediately. Am I making a mistake?


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Library FPCDLL; uses SysUtils; procedure TestExceptionRunError; stdcall; export;    begin   try      RunError(123);   except   end;   end; Procedure RunErrorToExcept (ErrNo : Longint; Address : CodePointer; Frame : Pointer);    begin   raise Exception.Create('Run error '+IntToStr(ErrNo));   end; exports   TestExceptionRunError; beginErrorProc:=@RunErrorToExcept;end. 
I call FPC compiler using the following FPC.cfg file for options.

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- -Twin32 -ve -S2 -Sc -Se -Sg -Sm -Sd -FeErrPrg.Log -Ci- -FuC:\FPC\3.2.2\units\i386-win32\fcl-base -gl -Rintel -MDelphi 
Could someone possibly give me an example of this kind of thing? I've seen that exception handling in a DLL is a boring topic, but I must not be the first one to break my teeth on this ?

Thanks in advance.

PascalDragon:
Some points:


* you don't need to set ErrorProc, because the default handler provided by the SysUtils unit already converts all run errors
* you don't need to declare your TestExceptionRunError as export as you have it in the exports clause
* your assumptions about the RunError function are wrong: it does not use the exception handling hooks, but always terminates; normal run errors (e.g. triggered by I/O errors) go through the HandleError*-family of functions (and not RunErrror) which are handled by the exception handling hooks and are not exported from the System unit (so to test this you need to trigger a run error some other way)
*

DenReq:
Hello PascalDragon,

Thank you for the reply and the informations.

Regards

Navigation

[0] Message Index

Go to full version