[fpc-pascal] Unhandled exception from library crashes host exe

kyan alfasud.ti at gmail.com
Wed Jun 27 15:58:14 CEST 2012


I am sure that this has been asked before but I couldn't find an answer.

I am in the process of porting a large application consisting of an
exe and many dlls from Delphi7 to FPC 2.7.1/Lazarus for Windows/WinCE
with hopes of being able to finally port it to Linux. I have managed
to overcome all obstacles but this seems like a brick wall: An
exception raised from a dll that is not handled by the dll's code will
crash the exe, bypassing any try/finally/except handlers around the
call into the dll that raised it. This is of course a complete
showstopper because the API and code of the dlls is way too massive to
re-engineer so that it does not let exceptions bubble up to the exe.

In Delphi without packages the aforementioned situation can be handled
reasonably well because despite the fact that operators "is" and "as"
won't work on the dll's Exception object (its class pointer points
inside the dll's Exception class and not the exe's Exception class) at
least the exception handlers work so one can display an error message
and keep the main application loop running. It is solved perfectly if
one builds all executables with runtime packages so that there is only
one Exception class for the exe and all dlls. But in FPC there are no
"runtime packages" in the Delphi sense, therefore there doesn't seem
to be a solution to this.

Can someone suggest a solution, even if I have to manually apply a
patch to FPC and build it myself? Because if there isn't one I will
have to scrap the whole project.

Thank you in advance.



More information about the fpc-pascal mailing list