如何使用Boost.Test库处理整数除零异常?

发布于 2024-12-20 19:07:04 字数 259 浏览 4 评论 0原文

我正在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花间憩 2024-12-27 19:07:04

由于它是 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文