Home EOverflow Exception and +INF in COM DLL
Reply: 0

EOverflow Exception and +INF in COM DLL

user8425066
1#
user8425066 Published in 2017-09-10 19:46:15Z

In Delphi Seattle, I have a calculation function of the following construct:

try
  result := ..... // calculation
except
  // Handle (overflow) exception
end;

Calling this function from an EXE, works as expected and the overflow exception is trapped and handled. However, calling the function from a COM DLL, the exception is not trapped. By debugging, I figured out that result becomes +INF and the EOverflow exception is not raised (which has a knock-on effect further in my code).

After some experimentation I figured out that changing the function to the following does work from the COM DLL:

try
  result := ..... // calculation
  if result = Infinity then
    raise EOverflow.Create('Forced overflow');
except
  // Handle (overflow) exception
end;

I suppose I could wrap the 'if result = ... ' code in an {$IFDEF MYFLAG} block so that it only compiles for the COM DLL (which is fine as a quick-fix), but I am wondering if there's a more elegant solution.

Doing some research on the web, I have come across the suggestion to use SetExceptionMask or the $FINITEFLOAT compiler directive. SetExceptionMask seems rather tricky (side effects?) and $FINITEFLOAT seems to have no effect, which I more or less expected since ON is supposed to be the default...

Moreover, the suggestions found are all for older (even .NET) versions of Delphi, which makes me a bit weary to apply it.

Any thoughts or suggestions? Thanks in advance for considering!

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.304143 second(s) , Gzip On .

© 2016 Powered by cudou.com design MATCHINFO