我在使用 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/