Test error reporting in CppUnit is done by throwing a custom exception type on it. We will call this CppUnitException here for simplicity.
CPPUNIT_ASSERT_THROW is a macro that will expand to what it essentially is:
try { expression; throw CppUnitException("Expected expression to throw"); } catch( const ExceptionType & e ) { }
If expression throws (as expected), we end up in a catch that does nothing.
If expression not thrown, execution proceeds to a line of code that throws a CppUnitException that will cause the test to fail.
Of course, the implementation of the CPPUNIT_ASSERT_THROW macro is actually a little more interesting, so the line and file information is also reported, but this is the general essence of how it works.
Michael anderson
source share