We are moving our code base from BDS2006 to Rad Studio XE, and we found a very strange behavior: if we did an invalid floating point operation (i.e. division by zero) after creating some object from the COM server embedded in. Net4.0, we do not get a normal exception (i.e. EDivisionByZero), but EStackOverflow.
We were able to prepare a very simple example: ComErrorExample
There is a .net 4.0 assembly with a com interface (one function return function) and a simple delphi application:
var a, b: Double; Stored8087CW: Word; begin CoInitialize(nil); try b := 0; a := 1 / b; except on E: Exception do Writeln(E.ClassName, ': ', E.Message, ' (Expected type of exception)'); end; Stored8087CW := Get8087CW; Writeln('Code from .NET COM: ', CoExampleOfCOM.Create.DoSomething); Set8087CW(Stored8087CW); //it only to show that 8087 control word doesn't change try b := 0; a := 1 / b; except on E: Exception do Writeln(E.ClassName, ': ', E.Message, ' (Unexpected type of exception! Why stack overflow?)'); end; Readln; CoUninitialize; end.
As you can see, we do two divisions by zero - first, one, before creating a com-object, throws EDivisionByZero, the second calls EStackOverflow.
We tested this on win7 x64, and winXp x32 - no difference. But when we switched the com server from .net4.0 to .net3.5, everything worked fine.
Question: are we doing something wrong? Can we do something to fix this problem?
Switching to .net3.5 or resetting Delphi is not an option for us.
UPDATE: We checked the floating point configuration (Set8087CW ()), but with no luck. UPDATE2: I have expanded the floating-point reconfiguration example.