We are migrating our codebase from BDS2006 to Rad Studio XE, and we found some very strange behavior: if we make invalid floating point operation (ie. division by zero) after creating some object from COM server implemented in .Net4.0, we don't get normal exception (ie. EDivisionByZero), but EStackOverflow.
We managed to prepare very simple example: ComErrorExample
There is an .net 4.0 assembly, with com interface (one function returning string) and 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's 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 make two divisions by zero - first one, before com object creation, throws EDivisionByZero, second one throws EStackOverflow.
We tested this on win7 x64, and winXP x32 - no difference. But when we switched com server from .net4.0 to .net3.5 - everything works fine.
Question: are we doing something wrong? Can we do something to fix this problem?
Switching to .net3.5, or dumping Delphi isn't an option for us.
UPDATE: We checked the floating point configuration ( Set8087CW() ) before but without any luck. UPDATE2: I've expanded example with restoring floating point configuration.