Search code examples
c++windowsunit-testingboost-testdivide-by-zero

How to handle Integer Division By Zero exception using Boost.Test library?


I'm writing unit tests using Boost.Test against some old C math library. One of tested functions in known to raise Integer Division By Zero system exception for some specified input. Let's say it's desired behavior and I want to write negative test for this case.

BOOST_REQUIRE_THROW(statement, exception); is not working for me as it is not C++ style exception (this macro is using try {} catch {} internally).

What is the correct way to handle case when I'm expecting failure on system level?


Solution

  • Since it's Windows, I suggest looking into _set_se_translator() Windows API. It allows to handle Structured Exception with C++ catch.

    There are other possible ways, such is installing your handlers, but this one allows uniform exception handling as if they were C++ exceptions with minimal programming effort.