Visual Assert – The Unit Testing Add-In for Visual C++
cfix – C/C++ Unit Testing for Win32 and NT
 
 

WIN_ASSERT_THROWS

WIN_ASSERT_THROWS

Synopsis

WIN_ASSERT_THROWS can be used to check that a given expression raises a specific exception. If the expected exvception is not raised, the condition is treated as a failure. If an exception of a different type is raised, this exception will be treated as an unhandled exception, which, depending on your settings, will either lead to a debugger breakin or to the test case being aborted.

Note that WIN_ASSERT_THROWS can only be used to check for exceptions that can be caught by reference.

Declaration
void WIN_ASSERT_FALSE( 
	Expression, 
	ExceptionType
	);
			
Parameters

[in] Expression: The expression that is expected to raise an exception. If Expression returns a value, this value will be ignored.

[in] ExceptionType: The class name of the expected exception.

[in] ...: Optional: Message to be included in a failure report. This parameter allows printf-style formatters to be used, with the corresponding parameters being specified as subsequent arguments. The routine is overloaded and allows Message to be either a unicode or an ANSI string.

Usage example
class TestException {};
static void RaiseTestException()
{
  throw TestException();
}

BEGIN_TEST( TestForRaisedException )
{
  WIN_ASSERT_THROWS( RaiseTestException(), TestException );
}
END_TEST
			
Requirements

Table 7.52. 

 User ModeKernel Mode
Available since1.3N/A
HeaderDeclared in winunit.hN/A
LibraryLink to cfix.libN/A
DLLcfix.dllN/A
IRQLN/AN/A

Requires cl version 14.00 (VisualStudio 2005) or better.