c++ - 捕获未捕获异常

标签 c++ c++11 catch-unit-test

我在使用 Catch 编写单元测试时遇到了一个问题,即我的测试因抛出异常而失败,尽管我使用了 REQUIRE_THROWS_AS。这是我的测试:

SECTION("Get column index for inexistent name") {
    REQUIRE_THROWS_AS(result->column_index("inexistent"), std::out_of_range);
}

这是我在控制台上遇到的异常:

$ tests/unit_tests "Test Result"
libc++abi.dylib: terminating with uncaught exception of type std::out_of_range: Name not found.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
unit_tests is a Catch v1.5.8 host application.
Run with -? for options

-------------------------------------------------------------------------------
Test Result
  Query empty table
  Get column index for inexistent name
-------------------------------------------------------------------------------
<path to file>:22
...............................................................................

<path to file>:46: FAILED:
due to a fatal error condition:
  SIGABRT - Abort (abnormal termination) signal

===============================================================================
test cases: 1 | 1 failed
assertions: 8 | 7 passed | 1 failed

如果我理解 Catch this exception 正是我要捕获的内容,对吧?

最佳答案

make clean 解决了这个问题。

关于c++ - 捕获未捕获异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41611973/

相关文章:

c++ - 如何使用带有最小化主窗口的 CreateProcess 启动控制台应用程序

C++ 从类方法返回对象数组

c++ - 用作模板参数的 lambda 正文中的右位移位在 GCC 上无法编译

c++ - 类中的 std::function 初始化

c++ - 如何提高 C++ 中的分支覆盖率

c++ - BOOST_PP_ITERATION 可变长度参数

c++ - std::bind2nd 的替代品

C++ STL 映射 : is access time O(1)?

c++ - C++ 中的异常和 BDD - Catch 库

c++ - 使用 Catch 库无法解析的外部符号