Thanks for the reply. I was hoping there might be an existing macro/feature I had overlooked, but I guess not.
I ended up creating a macro using a hybrid of the CHECK_THROW and QVERIFY macros:
#define QVERIFY_THROW(expression, ExpectedExceptionType) \
do \
{ \
bool caught_ = false; \
try { expression; } \
catch (ExpectedExceptionType const&) { caught_ = true; } \
catch (...) {} \
if (!QTest::qVerify(caught_, #expression ", " #ExpectedExceptionType, "", __FILE__, __LINE__))\
return; \
} while(0)
...
QVERIFY_THROW(foo(-1), std::invalid_argument);
#define QVERIFY_THROW(expression, ExpectedExceptionType) \
do \
{ \
bool caught_ = false; \
try { expression; } \
catch (ExpectedExceptionType const&) { caught_ = true; } \
catch (...) {} \
if (!QTest::qVerify(caught_, #expression ", " #ExpectedExceptionType, "", __FILE__, __LINE__))\
return; \
} while(0)
...
QVERIFY_THROW(foo(-1), std::invalid_argument);
To copy to clipboard, switch view to plain text mode
Pretty much the same as your 2nd suggestion. Seems to work fine.
Bookmarks