【问题标题】:Get google test exception throw message [duplicate]获取谷歌测试异常抛出消息[重复]
【发布时间】:2015-04-08 05:11:42
【问题描述】:
我正在为我的项目使用谷歌测试框架。我从代码中抛出异常:
throw DerivedClassException("message");
并在测试框架中使用:
ASSERT_THROW(commond(), DerivedClassException);
我想通过what() API 获取消息。
获取异常的确切异常消息的任何方式。
【问题讨论】:
标签:
c++
c++11
exception-handling
googletest
【解决方案1】:
检查抛出的异常的唯一方法是在测试中捕获它:
void test_foo( MyTest, TestException )
{
try
{
functionThatThrowsException();
FAIL();
}
catch( const DerivedClassException& err )
{
// check exception
ASSERT_STREQ( "error message", err.what() );
}
}