如何使用Boost.Test库处理整数除零异常?
我正在使用 Boost.Test 针对一些旧的 C 数学库编写单元测试。已知已测试函数之一会针对某些指定输入引发整数除零系统异常。假设这是期望的行为,我想为这种情况编写负面测试。
BOOST_REQUIRE_THROW(statement, exception);
对我不起作用,因为它不是 C++ 风格的异常(该宏在内部使用 try {} catch {}
)。
当我预计系统级别出现故障时,处理案例的正确方法是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于它是 Windows,我建议查看 _set_se_translator() Windows API。它允许使用 C++
catch
处理结构化异常。还有其他可能的方法,例如安装处理程序,但是这种方法允许统一的异常处理,就好像它们是 C++ 异常一样,并且只需最少的编程工作。
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.