In C++, exception handling can be tricky, especially when using Typemock Isolator++.
By default, Isolator++ catches exceptions in the code under test, but sometimes you need to handle them in your test code instead.
Isolator++ needs to know before a CallOriginal or Invoke is executed where exceptions should be caught. By default, exceptions are caught in the code under test.
The new HandleExceptionInTest flag informs Isolator++ to catch exceptions in the test code rather than in the code under test.
Without the flag, exceptions are handled as usual by the code you’re testing.
Example usage:
TEST_F(WhenToUse, HandleExceptionInTest)
{
// Create a fake under-test object that will call all original code but catch exceptions in the test
auto underTest = FAKE<ClassUnderTest>(FakeOptions::CallOriginal | FakeOptions::HandleExceptionInTest);
//Test that public method throws
WHEN_CALLED(underTest->MethodShouldThrow()).Throw("Hi");
//Assert throw
EXPECT_THROW(underTest->MethodShouldThrow(),exception);
}
In this example, Isolator++ will call the original method but handle any exceptions inside the test, not the under-test code.
Use this flag when you need direct control over exception verification in your tests.



