Jump to content
  • Advertisement
Sign in to follow this  

Win32 Exceptions

This topic is 2820 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I have a small problem regarding Win32 exceptions like overflow, division by zero, etc...

I have to work with some legacy code that performs all kind of ugly operations and casts doubles to integers without validating the parameters first. Although I've disabled floating point exceptions (through the project's code generation property sheet), an "invalid floating point operation" is still thrown at some point, when casting a double to an unsigned short (the double is way too high, but I'm required to ignore it). What could be responsible for throwing that exception in the first place and what can I do to simply ignore it?

Share this post


Link to post
Share on other sites
Advertisement
Did you try _controlfp_s?

Something like this should do:


#include <float.h>

unsigned int currentControl;
// Disable floating point exceptions
_controlfp_s(¤tControl, 0, _MCW_EM);

// Restore previous state
_controlfp_s(¤tControl, currentControl, _MCW_EM);

Share this post


Link to post
Share on other sites
Thank you very much. I didn't know it was possible to change whether or not hardware exceptions are thrown during runtime, though I suspected it, due to the particular nature of the problem.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!