Question

I'm using googletest and in many of my tests I use the ASSERT_THROW command. The problem is that if, for example, it throws a different exception than the one I expected, all I get is:

Actual: it throws a different type.

Is there some way to get it to spit out the return value of what() or something?

Was it helpful?

Solution

You probably throw by pointer (using new keyword)

throw new MyDerivedException();

and expected to receive a non-pointer type of exception:

EXPECT_THROW(blah, MyDerivedException);

You should throw by value.

throw MyDerivedException(); // notice lack of 'new'

OTHER TIPS

throw new MyDerivedException() ... EXPECT_THROW(blah, MyDerivedException*);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top