Environment Windows 10 with MSVC2015 professional, compile with /EHa
What I'm doing: enabling floating point exception to be able to catch exceptions when some bad things happen, just for debuging
code:
namespace debug_details
{
void (*defaultStructuredExceptionFunc)(unsigned int, PEXCEPTION_POINTERS) = nullptr;
void my_trans_func(unsigned int exceptionCode, PEXCEPTION_POINTERS pExpInfo)
{
switch (exceptionCode)
{
case EXCEPTION_FLT_DENORMAL_OPERAND:
case EXCEPTION_FLT_DIVIDE_BY_ZERO:
case EXCEPTION_FLT_INEXACT_RESULT:
case EXCEPTION_FLT_INVALID_OPERATION:
case EXCEPTION_FLT_OVERFLOW:
case EXCEPTION_FLT_STACK_CHECK:
case EXCEPTION_FLT_UNDERFLOW:
{
_clearfp();
std::stringstream ss;
ss << "floating-point structured exception: 0x" << std::hex << exceptionCode;
throw std::runtime_error(ss.str());
}
default:
if (defaultStructuredExceptionFunc != nullptr)
{
defaultStructuredExceptionFunc(exceptionCode, pExpInfo);
}
};
};
void EnableFloatingPointExceptions()
{
unsigned int fe_value = ~(/*_EM_INVALID | _EM_DENORMAL |*/ _EM_ZERODIVIDE | _EM_OVERFLOW | _EM_UNDERFLOW /* | _EM_INEXACT*/);
unsigned int mask = _MCW_EM;
unsigned int currentWord = 0;
_clearfp();
errno_t result = _controlfp_s(¤tWord, fe_value, mask); // https://msdn.microsoft.com/en-us/library/c9676k6h.aspx
DVASSERT(result == 0);
debug_details::defaultStructuredExceptionFunc = _set_se_translator(&debug_details::my_trans_func); // https://msdn.microsoft.com/en-us/library/5z4bw5h5.aspx
float32 div = 0.f;
float32 f = 15.f / div;
float32 f2 = 30.f * div;
}
} // end namespace debug_details
I expect EXCEPTION_FLT_DIVIDE_BY_ZERO, but have
Please help to understand what is going on? Thanks in advance!