When I get a floating point to zero exception when using TWebBrowser and TEmbeddedWB from time to time, I find that I need to mask the division by zero of the Set8087CW or SetMXCSR exceptions.
Q1: What would be the best way to do this:
- to mask such exceptions at an early stage of application launch and never touch them (application is multithreaded)?
- to use the
OnBeforeNavigate and OnDocumentComplete to mask / remove the exception mask? (is there any chance that an exception may occur after loading the document?)
Q2: What would be the best “command” to mask only “division by zero”, and nothing else - if the application is 32-bit, do you also need to mask the exception from 64 bits?
In the application I use, it has TWebBrowser, available all the time to display the contents of the email.
Also, if anyone can clarify, is this a special mistake using Microsoft's TWebBrowser or is it just the difference between Delphi / C ++ Builder and Microsoft tools? What happens if I place TWebBrowser inside a Visual C ++ application, if division by zero error appears - it will not be thrown into the exception, but what then happens - how does Visual C ++ handle the division by zero exception, what?
Oddly enough, Microsoft has not noticed this problem for such a long time - it is also strange that Embarcardero did not notice it. Since masking floating point exceptions effectively also masks your own program exception for that particular purpose.
UPDATE
My final decision after some study:
SetExceptionMask(GetExceptionMask() << exZeroDivide);
The default state from GetExceptionMask () returns: TFPUExceptionMask() << exDenormalized << exUnderflow << exPrecision . Obviously, some exceptions are already masked - this simply adds exZeroDivide to the masked exceptions.
As a result, each division by zero now leads to + INF at the floating point instead of an exception. I can live with this - for the production version of the code, it will be masked to avoid errors, and for the debug version it will be exposed to detect floating point division by zero.
exception delphi c ++ builder webbrowser-control twebbrowser
Coder12345
source share