I want to test that MyException is thrown in a certain case. EXPECT_THROW is good here. But I also want to check the exception has a specific state
My version; it produces the same output as EXPECT_THROW and just adds the string test:
#define EXPECT_THROW_MSG(statement, expected_exception, expected_what) \
try \
{ \
statement; \
FAIL() << "Expected: " #statement " throws an exception of type " #expected_exception \
".\n" \
" Actual: it throws nothing."; \
} \
catch (const expected_exception& e) \
{ \
EXPECT_EQ(expected_what, std::string{e.what()}); \
} \
catch (...) \
{ \
FAIL() << "Expected: " #statement " throws an exception of type " #expected_exception \
".\n" \
" Actual: it throws a different type."; \
}