抓住没有捕获异常

时间:2017-01-12 11:23:24

标签: 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这个例外正是我试图抓住的那个?

1 个答案:

答案 0 :(得分:0)

make clean解决了这个问题。