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

Reinier Olislagers reinierolislagers at gmail.com
Wed Jun 27 16:38:48 CEST 2012

On 27-6-2012 16:22, Antonio Fortuny wrote:
> Le 27/06/2012 16:14, OBones a écrit :
>> Hello,
>> Regular exceptions, those raised with the "raise" keyword are always
>> trapped by try..except blocks but you have to make sure that EVERY
>> method in the DLL that is called by the host exe has such a construct
>> so as not to let the exception escape.
>> However, there are exceptions that come from the FPU and that arise
>> when doing floating point maths. Those, in a DLL, are not trapped by
>> the try..except blocks and are passed back to the host exe,
>> effectively crashing them.
>> If you want to trap them, you have to add a special unit in your DLL
>> project, as explained in this issue:
>> http://bugs.freepascal.org/view.php?id=12974
> I read quickly the las post and seems encouraging. I'll try it in my UDF
> (64bit, windows, Michael is right) and report any discrepancy but not
> before next week.

Would compiling FPC with the SEH exception handling code
(-dTEST_WIN64_SEH) instead of that unit work in this context?

It worked for me with Win64 embedded (i.e. dll+exe in same memory space)
when dealing with exceptions inside the FB dll that incorrectly bubbled
up to the exe. Unfortunately I don't know enough to tell if this would
also improve FPU exception behaviour...

See e.g. last comment in this bug:


More information about the fpc-pascal mailing list