Reasons why an exception thrown from googlemock can't be caught

67 views
Skip to first unread message

Edwin Vane

unread,
Nov 1, 2016, 8:43:07 PM11/1/16
to Google C++ Mocking Framework
Hi,

This strange problem is probably not an issue with googlemock itself but perhaps in the way it is built. I was hoping for ideas on where to start debugging.

I have some code-under-test like this:

try {
   ...
   dep->doSomething(...)
   ...
} catch (const MyException& e) {
...
}

And some test code like this:

EXPECT_CALL(&depMock, doSomething(...)).WillOnce(Throw(MyException{"message"}));

The exception is thrown and escapes the catch and causes the test to fail. This happens even with standard exceptions. MyException inherits from std::exception. It's almost like whatever runtime type test is happening as part of that catch statement is not matching the type of the thrown exception properly even though they're named the same. I'm building with gcc 4.9. I'm using libc++ for the standard library. 

Any thoughts?
Reply all
Reply to author
Forward
0 new messages